ylizml

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

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

image
服务端获取微信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获得微信接口权限成功
image

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

分类:

技术点:

相关文章:

  • 2022-01-21
  • 2022-12-23
  • 2021-08-16
  • 2021-12-04
  • 2021-11-25
  • 2021-11-17
  • 2021-10-24
猜你喜欢
  • 2021-09-07
  • 2022-12-23
  • 2021-12-10
  • 2021-11-03
  • 2022-02-13
相关资源
相似解决方案