php官方微信接口大全(微信支付、微信红包、微(2)

<?php require_once 'lib.inc.php'; $wx = new WxApi(); if(!isset($_GET['code'])){ header("location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=".WxApi::appId."&redirect_uri=http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."&response_type=code&scope=snsapi_base&state=1#wechat_redirect"); } else{ $CODE = $_GET['code']; $Info = $wx->wxOauthAccessToken($CODE); //print_r($Info); $openId = $Info['openid']; } $signPackage = $wx->wxJsapiPackage(); ?> <html> <head> <title>JSAPI接口测试</title> <meta charset="UTF-8"> <meta content="width=device-width, initial-scale=1.0"> <script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <script> wx.config({ debug: true, appId: '<?php echo $signPackage["appId"];?>', timestamp: <?php echo $signPackage["timestamp"];?>, nonceStr: '<?php echo $signPackage["nonceStr"];?>', signature: '<?php echo $signPackage["signature"];?>', jsApiList: [ // 所有要调用的 API 都要加到这个列表中 'onMenuShareTimeline', 'onMenuShareAppMessage' ] }); wx.ready(function () { // 在这里调用 API wx.onMenuShareAppMessage({ title: '互联网之子', desc: '在长大的过程中,我才慢慢发现,我身边的所有事,别人跟我说的所有事,那些所谓本来如此,注定如此的事,它们其实没有非得如此,事情是可以改变的。更重要的是,有些事既然错了,那就该做出改变。', link: 'http://movie.douban.com/subject/25785114/', imgUrl: 'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg', trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 alert('用户点击发送给朋友'); }, success: function (res) { alert('已分享'); }, cancel: function (res) { alert('已取消'); }, fail: function (res) { alert(JSON.stringify(res)); } }); wx.onMenuShareTimeline({ title: '互联网之子', link: 'http://movie.douban.com/subject/25785114/', imgUrl: 'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg', trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 alert('用户点击分享到朋友圈'); }, success: function (res) { alert('已分享'); }, cancel: function (res) { alert('已取消'); }, fail: function (res) { alert(JSON.stringify(res)); } }); }); var readyFunc = function onBridgeReady() { document.querySelector('#batchAddCard').addEventListener('click',function(e) { WeixinJSBridge.invoke('batchAddCard', { "card_list": [<?php echo $kqInfo;?>] }, function(res) { alert(res.err_msg + " _ " + res.card_list); }); }); } if (typeof WeixinJSBridge === "undefined") { document.addEventListener('WeixinJSBridgeReady', readyFunc, false); } else { readyFunc(); } </script> </head> <body> <div> <input type="button" value="添加卡券" /> </div> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/20ca2c7dcc5e4db479b3beea19fefa57.html