我的是php,首先要做一个php的函数(我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 |
function jssdk(){ $appid = '这里替换成你的appid'; $secret = '这里替换成你的key'; $_title = '微信'; $code = $_GET['code'];//获取code $_SESSION['code'] = $code;//设置code缓存给微信付账使用 $auth = file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code");//通过code换取网页授权access_token $jsonauth = json_decode($auth); //对JSON格式的字符串进行编码 $arrayauth = get_object_vars($jsonauth);//转换成数组 $openid = $arrayauth['openid'];//输出openid $access_token = $arrayauth['access_token']; $_SESSION['openid'] = $openid; $accesstoken = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."");//获取access_token $token = json_decode($accesstoken); //对JSON格式的字符串进行编码 $t = get_object_vars($token);//转换成数组 $access_token = $t['access_token'];//输出access_token $jsapi = file_get_contents("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi"); $jsapi = json_decode($jsapi); $j = get_object_vars($jsapi); $jsapi = $j['ticket'];//get JSAPI $time = 14999923234; $noncestr= $time; $jsapi_ticket= $jsapi; $timestamp=$time; $and = "jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."×tamp=".$timestamp."&url=".$url.""; $signature = sha1($and); return $signature; } |
|
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
57
58
59
60
61
62
63
64
65
66
67
68 |
<script language="javascript" type="text/javascript">wx.config({ debug: false,//这里是开启测试,如果设置为true,则打开每个步骤,都会有提示,是否成功或者失败 appId: '这里换成你的appid', timestamp: '14999923234',//这个一定要与上面的php代码里的一样。 nonceStr: '14999923234',//这个一定要与上面的php代码里的一样。 signature: '<?=jssdk();?>', jsApiList: [ // 所有要调用的 API 都要加到这个列表中 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo' ]});wx.ready(function () { wx.onMenuShareTimeline({ title: "<?=$act['act_name']?>", // 分享标题 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); wx.onMenuShareAppMessage({ title: "<?=$act['act_name']?>", // 分享标题 desc: "<?=substr($act['act_stime'],0,10)?><?=$act['act_place']?>", // 分享描述 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); wx.onMenuShareQQ({ title: "<?=$act['act_name']?>", // 分享标题 desc: "<?=substr($act['act_stime'],0,10)?>n<?=$act['act_place']?>", // 分享描述 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); wx.onMenuShareWeibo({ title: "<?=$act['act_name']?>", // 分享标题 desc: "<?=substr($act['act_stime'],0,10)?>n<?=$act['act_place']?>", // 分享描述 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } });});</script> |
赣公网安备36010402000493
评论回复