[Overview] Enterprise micro-letter web developer, the ability to call native essential, so, how to use JS-SDK to achieve?
[Official document] https://work.weixin.qq.com/api/doc#10029/
【step】
step1: in full accordance with the manual operation can be as follows
step2: config in obtaining the required configuration data (supplement)
Reference API server configuration https://work.weixin.qq.com/api/doc#90000/90135/90664 and JS-SDK documentation https://work.weixin.qq.com/api/doc#90000/90136 / 90506 to obtain application signature
Reference herein can be directly used in a method PHP Demo (refer to Part I: https://blog.csdn.net/gzyh_tech/article/details/88565966 ):
Obtain configuration information such as signature and time stamp
/**获取jsqpi**/
$jsapiTicket=$api->JsApiTicketGet();
$nonceStr=createNonceStr();
$timestamp=time();
$jsapi=$api->JsApiSignatureGet($jsapiTicket, $nonceStr, $timestamp, getUrl());
So write in the page js:
wx.config({
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '<?php echo $config['CORP_ID']?>', // 必填,企业微信的corpID
timestamp:'<?php echo $timestamp?>' , // 必填,生成签名的时间戳
nonceStr: '<?php echo $nonceStr?>', // 必填,生成签名的随机串
signature: '<?php echo $jsapi?>',// 必填,签名,见附录1
jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
This is configured, basic usage is as follows:
wx.ready(function () {
//TODO: 执行和jsapi相关的初始化操作
//二维码扫描
$("#scan").on("click",function(){
wx.scanQRCode({
desc: 'scanQRCode desc',
needResult: 1, // 默认为0,扫描结果由企业微信处理,1则直接返回扫描结果,
scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是条形码(一维码),默认二者都有
success: function(res) {
// 回调resultStr&errMsg
},
error: function(res) {
if (res.errMsg.indexOf('function_not_exist') > 0) {
alert('版本过低请升级');
return;
}
alert(res.errMsg)
}
});
})
});