problem description
Wechat JSSDK config displays OK,checkJsApi, shows OK, and then there is no response. It does not play the sharing interface and does not report an error
.the environmental background of the problems and what methods you have tried
I have seen a lot of cases on the Internet, but I did not succeed. This is my test address http://ecapex.top/wx/sample/p.
asks the boss for advice, what is the reason
related codes
/ / Please paste the code text below (do not replace the code with pictures)
this is the front-end code
<?php
require_once "jssdk.php";
$jssdk = new JSSDK("Appid", "APPSecret");
$signPackage = $jssdk->GetSignPackage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js">
<script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.js"></script>
<script>
wx.config({
debug: true,
appId: "<?php echo $signPackage["appId"];?>",
timestamp: <?php echo $signPackage["timestamp"];?>,
nonceStr: "<?php echo $signPackage["nonceStr"];?>",
signature: "<?php echo $signPackage["signature"];?>",
jsApiList: [
// API
"updateAppMessageShareData",
"updateTimelineShareData",
"onMenuShareAppMessage",
"onMenuShareTimeline"
]
});
//json
window.share_config = {
"share": {
"imgUrl": "https://img.codeshelper.com/upload/img/2021/06/17/yzsmigqtui018139.jpg",//"http://"
"desc" : "",//,
"title" : "",//
"link": "http://ecapex.top",//
"success":function(){//
},
"cancel": function () {
//
}
}
};
wx.ready(function () {
// API
//JS
wx.checkJsApi({
jsApiList: [
// API
"updateAppMessageShareData",
"updateTimelineShareData",
"onMenuShareAppMessage",
"onMenuShareTimeline"
], // JSJS2,
success: function(res) {
console.log(res)
// apitruefalse
// :{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
});
});
function AppMessage() {
wx.updateAppMessageShareData(share_config.share);
}
function Timeline() {
wx.updateTimelineShareData(share_config.share);
}
function Messages() {
wx.onMenuShareAppMessage(share_config.share);
}
function timelines() {
wx.onMenuShareTimeline(share_config.share)
}
</script>
<button onclick="AppMessage()"></button><br>
<button onclick="Timeline()"></button><br>
<button onclick="Messages()"></button>
<button onclick="timelines()"></button>
</html>
this is the back-end code
<?php
class JSSDK {
private $appId;
private $appSecret;
public function __construct($appId, $appSecret) {
$this->appId = $appId;
$this->appSecret = $appSecret;
}
public function getSignPackage() {
$jsapiTicket = $this->getJsApiTicket();
// URL hardcode.
$protocol = (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] !== "off" || $_SERVER["SERVER_PORT"] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = $this->createNonceStr();
// key ASCII
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signature = sha1($string);
$signPackage = array(
"appId" => $this->appId,
"nonceStr" => $nonceStr,//
"timestamp" => $timestamp,//
"url" => $url,//URL
"signature" => $signature,//
"rawString" => $string
);
return $signPackage;
}
//ASCII
private function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $iPP) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
//ticket
private function getJsApiTicket() {
// jsapi_ticket
$data = json_decode($this->get_php_file("jsapi_ticket.php"));
if ($data->expire_time < time()) {
$accessToken = $this->getAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
$res = json_decode($this->httpGet($url));
$ticket = $res->ticket;
if ($ticket) {
$data->expire_time = time() + 7000;
$data->jsapi_ticket = $ticket;
$this->set_php_file("jsapi_ticket.php", json_encode($data));
}
} else {
$ticket = $data->jsapi_ticket;
}
return $ticket;
}
//accesstoken
private function getAccessToken() {
// access_token
$data = json_decode($this->get_php_file("access_token.php"));
if ($data->expire_time < time()) {
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
$res = json_decode($this->httpGet($url));
$access_token = $res->access_token;
if ($access_token) {
$data->expire_time = time() + 7000;
$data->access_token = $access_token;
$this->set_php_file("access_token.php", json_encode($data));
}
} else {
$access_token = $data->access_token;
}
return $access_token;
}
private function httpGet($url,$type="get",$res="json",$arr="")
{
$ch = curl_init();
if (class_exists("\CURLFile")) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
} else {
if (defined("CURLOPT_SAFE_UPLOAD")) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if($type=="post"){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
if($res=="json"){
if( curl_errno($ch) ){
//
return curl_error($ch);
curl_close($ch);
}else{
//
curl_close($ch);
return $output;
}
}
}
//accesstokenticket
private function get_php_file($filename) {
return trim(substr(file_get_contents($filename), 15));
}
//accesstokenticket
private function set_php_file($filename, $content) {
$fp = fopen($filename, "w");
fwrite($fp, "<?php exit();?>" . $content);
fclose($fp);
}
}
what result do you expect? What is the error message actually seen?
is there any boss to help me see what the reason is? Give me some guidance, wait online