configured in accordance with the tutorials, directly choose to get access_token and jsapi_tikcet without cache, but the returned values are all ok. I don"t know why I chose to share them with friends or moments after this configuration, but I didn"t see the value returned by api. Can anyone with good intentions help me to see what"s wrong?
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title></title>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
</head>
<body>
<div class="page-content">
<?php
//access_token
$appid = "";//appid
$secret = ""; //secret
$request_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$request_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // SSL
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//,
$data=curl_exec($ch);
curl_close($ch);
$result=json_decode($data,true);
$access_token = $result["access_token"];
//jsapi_ticket
$request_url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$request_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // SSL
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//,
$data=curl_exec($ch);
curl_close($ch);
$result=json_decode($data,true);
$jsapi_ticket = $result["ticket"];
//16
function generate_noncestr($length = 16){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$noncestr = "";
for ( $i = 0; $i < $length; $iPP ){
$noncestr .= $chars[ mt_rand(0, strlen($chars) - 1) ];
}
return $noncestr;
}
$noncestr = generate_noncestr();
//
$timestamp = time();
$url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$string1 = "jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."×tamp=".$timestamp."&url=".$url;
$signature = sha1($string1);
?>
<script type="text/javascript">
wx.config({
debug: true, // ,apialertpclogpc
appId: "<?php echo $appid; ?>", //
timestamp: "<?php echo $timestamp; ?>", //
nonceStr: "<?php echo $noncestr; ?>", //
signature: "<?php echo $signature; ?>",//
jsApiList: [
"onMenuShareTimeline",
"onMenuShareAppMessage",
] // JS
});
wx.ready(function(){
wx.onMenuShareTimeline({
title: "test1", //
link: "http://baidu.com", // JS
imgUrl: "https://img.codeshelper.com/upload/img/2021/03/20/zhpmlp4hoj511273.gif", //
success: function () {
//
alert("");
},
cancel: function() {
alert("");
}
)};
wx.onMenuShareAppMessage({
title: "test1", //
desc: "test baidu", //
link: "http://baidu.com", // JS
imgUrl: "https://img.codeshelper.com/upload/img/2021/03/20/zhpmlp4hoj511273.gif", //
type: "link", // ,musicvideolinklink
dataUrl: "", // typemusicvideo
success: function () {
//
alert("");
}
cancel: function () {
//
alert("");
}
});
});
wx.error(function(res){
alert("error");
});
</script>
</div>
</body>
</html>