微信js-sdk调用一些接口,比如企业微信集成选人接口,需要注入agentconfig,官方说法是需要加载 https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js
但是这个文件里面只有agentconfig函数,可以通过控制台
[
"config",
"ready",
"error",
"checkJsApi",
"onMenuShareTimeline",
"onMenuShareAppMessage",
"onMenuShareQQ",
"onMenuShareWeibo",
"onMenuShareQZone",
"startRecord",
"stopRecord",
"onVoiceRecordEnd",
"playVoice",
"pauseVoice",
"stopVoice",
"onVoicePlayEnd",
"uploadVoice",
"downloadVoice",
"translateVoice",
"chooseImage",
"getLocation",
"previewImage",
"uploadImage",
"downloadImage",
"getLocalImgData",
"getNetworkType",
"openLocation",
"hideOptionMenu",
"showOptionMenu",
"closeWindow",
"hideMenuItems",
"showMenuItems",
"hideAllNonBaseMenuItem",
"showAllNonBaseMenuItem",
"scanQRCode",
"openAddress",
"openProductSpecificView",
"addCard",
"chooseCard",
"openCard",
"consumeAndShareCard",
"chooseWXPay",
"openEnterpriseRedPacket",
"startSearchBeacons",
"stopSearchBeacons",
"onSearchBeacons",
"openEnterpriseChat",
"agentConfig"
]
页面写入顺序如下:
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>
<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js" type="text/javascript"></script>
这样是不行的,虽然jweixin写在上面,但是文件大,可能加载在jwxwork后面,导致wx对象仍没有agentconfig函数。晚上有个说法是调用1.0.0文件,https://res.wx.qq.com/wwopen/js/jsapi/jweixin-1.0.0.js,这个文件里有agentconfig函数,但是是旧版的。
综上,解决办法是手动加载js文件
参考:https://www.cnblogs.com/xiaoniaohhl/p/11254272.html
页面中js加载完全的方法
function loadScript( url, callback) { var script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState) { script.onreadystatechange = function() { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } } } else { script.onload = function() { callback(); } } script.src = url; document.getElementsByName("head")[0].appendChild(script); } |
如何让脚本的执行顺序按照你设定的顺序执行,使用嵌套的方式:
loadScript("file1.js", function() { loadScript("file2.js", function() { loadScript("file3.js", function() { alert("All files are loaded"); }); }); }); |