forked from zoujingli/wechat-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
56 lines (48 loc) · 1.48 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
# 引入文件
require 'include.php';
# 配置参数
$config = array(
'token' => '',
'appid' => '',
'appsecret' => '',
'encodingaeskey' => '',
);
# 加载对应操作接口
$wechat = &\Wechat\Loader::get('User', $config);
$userlist = $wechat->getUserList();
var_dump($userlist);
var_dump($wechat->errMsg);
var_dump($wechat->errCode);
exit;
// 第三方平台 JSSDK 签名包
$wechat = Db::table('wechat_config')->where('authorizer_appid', 'wx60a43dd8161666d4')->find();
// 第三方授权获取到的 Access_token
$access_token = $wechat['authorizer_access_token'];
// 参与授权的公众号 APPID
$authorizer_appid = $wechat['authorizer_appid'];
// 当前微信页面URL地址(完整)
$current_url = url('', '', true, true);
// 实例SDK脚本
$script = load_wechat('Script', $authorizer_appid);
// 获取JS签名包
$result = $script->getJsSign($current_url, 0, '', $authorizer_appid, $access_token);
dump($result);
dump([$script->errMsg, $script->errCode]);
$json = json_encode($result, JSON_PRETTY_PRINT);
echo '<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>';
echo "
<script>
// JSSDK 错误处理
wx.error(function(){
//alert(JSON.stringify(arguments));
});
// JSSDK 配置参数
wx.config({$json});
// JSSDK 初始化成功
wx.ready(function(){
alert('初始化成功!');
wx.hideOptionMenu();
});
</script>
";