1.获取微信公众号信息

    1. public function getlocation(){
    2. $wechatInfo = D('Mp')->find(3);
    3. $options = array(
    4. 'token' => $wechatInfo['valid_token'],
    5. 'encodingaeskey' => $wechatInfo['encodingaeskey'],
    6. 'appid' => $wechatInfo['appid'],
    7. 'appsecret' => $wechatInfo['appsecret']
    8. );
    9. $wechatObj = new Wechat($options);
    10. $data = $wechatObj->getJsSign(I('get.url'));
    11. $this->ajaxReturn($data);
    12. }

    2.

    1. //调用微信sdk
    2. //<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    3. function setWechatJSSDK(res){
    4. wx.config({
    5. debug: false,
    6. appId: res.appId,
    7. timestamp: res.timestamp,
    8. nonceStr: res.nonceStr,
    9. signature: res.signature,
    10. jsApiList: [
    11. 'getLocation',
    12. 'scanQRCode'
    13. ]
    14. });
    15. /*
    16. 微信扫一扫
    17. author:咔咔
    18. time:6.11
    19. */
    20. $('.getqrcode').click(function(){
    21. wx.scanQRCode({
    22. needResult: 1,
    23. scanType : [ "qrCode"],
    24. desc: 'scanQRCode desc',
    25. success: function (res) {
    26. var id = res.resultStr.split('=')[1];
    27. }
    28. });
    29. })
    30. }
    31. function loadWechatJSSDK() {
    32. $.get("{:U('addon/WeiuidDeit/Mobile/getlocation')}",{url:location.href}, function (res) {
    33. setWechatJSSDK(res);
    34. });
    35. }
    36. setTimeout(loadWechatJSSDK, 500);