微信開發+百度AI學習:微信網頁開發環境搭建

參考微信官方文檔:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
兩步便可獲取微信網頁開發能力微信

STEP1:安裝微信公衆號開發nuget,裏面封裝了微信開發所須要的全部接口微信開發

image
服務端獲取微信JS-SDK簽名app

public JsonResult GetJsApi(string url)
{
    string timestamp = JSSDKHelper.GetTimestamp();
    string nonceStr = JSSDKHelper.GetNoncestr();

    string ticket = Senparc.Weixin.MP.Containers.JsApiTicketContainer.TryGetJsApiTicket(ApiConfig.AppID, ApiConfig.AppSecret);
    string signature = JSSDKHelper.GetSignature(ticket, nonceStr, timestamp, url);
    
    return Json(new { appId = ApiConfig.AppID, timestamp, nonceStr, signature }, JsonRequestBehavior.AllowGet);
}

STEP1:頁面調用js得到微信接口權限成功
imageide

/*
微信jsAPI
*/
(function ($, navigator) {
    var ant_js_config;
    var init_ant_js = function () {
        wx.config({
            debug: false,
            appId: ant_js_config.appId,
            timestamp: ant_js_config.timestamp,
            nonceStr: ant_js_config.nonceStr,
            signature: ant_js_config.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'
            ]
        });

    }

    $.getJSON('/common/GetJsApi', {
        'url': window.location.href
    }, function (result) {
        if (result) {
            ant_js_config = result;
            init_ant_js();
        }
    });
})(jQuery, navigator);
相關文章
相關標籤/搜索