take a look at the whitelist of Wechat platform added under ip.
or troubleshoot the splicing link problem.
for security reasons, developers must implement the logic of signing on the server side.
so,
wx.config({
debug: true, // ,apialertpclogpc
appId: '', //
timestamp: , //
nonceStr: '', //
signature: '',//
jsApiList: [] // JS
});
except for debug
and jsApiList
, all the fields needed for
frontend initialization are taken from the background. You wrote them dead in the foreground, so you made a mistake.
so, the usual logic is for the front end to get the above fields from the background, complete initialization at the front end, and then add callbacks for successful and failed initialization. Example:
var link = location.href
$.ajax({
url: 'your_url', //
type: 'GET',
data: { url: link },
async: true,
dataType: 'json',
success: function(data) {
wx.config({
debug: false, // ,apialert
appId: data.configMap.appId, //
timestamp: data.configMap.timestamp, //
nonceStr: data.configMap.nonceStr, //
signature: data.configMap.signature, // 1
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // JSJS2
})
wx.ready(function(res) {
wx.onMenuShareAppMessage({
title: document.title,
desc: document.title,
link: link,
imgUrl: Imgurl,
trigger: function(res) {},
success: function(res) {},
cancel: function(res) {},
fail: function(res) {}
})
wx.onMenuShareTimeline({
title: document.title,
link: link,
imgUrl: Imgurl,
trigger: function(res) {},
success: function(res) {},
cancel: function(res) {},
fail: function(res) {}
})
})
wx.error(function(res) {
alert(res)
})
},
error: function(error) {
alert(error)
}
})