原创

进一步封装微信JS SDK,使开发人员对JS SDk透明

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/SakuraLLj/article/details/46314627

1、进一步封装微信的JS SDK,使开发人员在使用JS SDk相关功能时,只需在页面上引入一次Script,不再需要引用微信的js及进行config的注入配置等;

2、在页面中引入此代码<scriptsrc=" http://127.0.0.1/weixin/jssdk.js?currpageurl=http://ee"></script>即可完成引入微信的js及通过config接口注入权限配置;

3、流程:

  1. 页面引入<scriptsrc=" http://127.0.0.1/weixin/jssdk.js?currpageurl=http://ee"></script>
  2. 页面向服务器请求http://127.0.0.1/weixin/jssdk.js?currpageurl=http://ee
  3. 服务器响应http://127.0.0.1/weixin/jssdk.js?currpageurl=http://ee
  4. jssdk.js对应的Action从服务器获得config需要的参数(appid、timestamp、nonceStr、signature),并返回
    document.write("<script type='text/javascript' src='http://http://res.wx.qq.com/open/js/jweixin-1.0.0.js'>" + "</scr" + "ipt>");
    var wxjssdkConfigData = {
        "debug": {{ debug }},
        "appId": "{{ appId }}",
        "timestamp": "{{ timestamp }}",
        "nonceStr": "{{ nonceStr }}",
        "signature": "{{ signature }}"
    };
    document.write("<script type='text/javascript' src='http://127.0.0.1/weixin/js/jssdkconfig.js') }}'>" + "</scr" + "ipt>");
  5. jssdkconfig.js:
    wx.config({
        debug:wxjssdkConfigData.debug,
        appId: wxjssdkConfigData.appId,
        timestamp: wxjssdkConfigData.timestamp,
        nonceStr: wxjssdkConfigData.nonceStr,
        signature: wxjssdkConfigData.signature,
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onRecordEnd',
            'playVoice',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ]
    });

文章最后发布于: 2015-06-01 18:04:22
展开阅读全文
0 个人打赏

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览