微信开发+百度AI学习:微信网页开发环境搭建

参考微信官方文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
两步即可获取微信网页开发能力

STEP1:安装微信公众号开发nuget,里面封装了微信开发所需要的所有接口

微信开发+百度AI学习:微信网页开发环境搭建
服务端获取微信JS-SDK签名

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获得微信接口权限成功
微信开发+百度AI学习:微信网页开发环境搭建

/*
微信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);