Wechat obtains the user's geographic location

6. Make sure that the url you get for signature is obtained dynamically. For the dynamic page, see how php is implemented in the example code. If the static page of html sends url to the backend for signature through ajax, the frontend needs to use js to obtain the link to remove the"- sharp"hash part of the current page (location.href.split ("- sharp") [0] is available), and encodeURIComponent), is required because once the page is shared, Wechat client will add other parameters at the end of your link. If the current link is not dynamically obtained, the shared page signature will fail.

php file test.php
require_once". / include/common.inc.php";
require_once". / jssdk.php";

if ($act = = "ajax") {

  $jsdk = new JSSDK($weixin_appID,$weixin_appSecret);

  $code = $jsdk->getSignPackage();
  echo json_encode($code);
  exit;

}
include template ("test.htm",_TPLWeixinPath_);
html file test.html

< html lang= "en" >
< head >

<meta charset="UTF-8">
<title></title>
<script src="./js/jquery-2.1.4.js"></script>
<script src="./js/test.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

< / head >
< body >

<div style="width:100px;height:100px;border:1px solid green;background:pink;" id="sun"></div>

< / body >
< / html >
js file test.js
/ / alert (1);
$(document) .on ("click","-sharpsun", function () {

)
    $.ajax({
        url: "test.php",
        data:{ act:"ajax"},
        type:"post",
        success:function(res){
                //console.log(res);
                var data = JSON.parse(res);
                wx.config({
                    debug: true,
                    appId: data.appId,
                    timestamp: data.timestamp,
                    nonceStr: data.nonceStr,
                    signature: data.signature,
                    jsApiList: [
                        //  API 
                        "checkJsApi",
                        "openLocation",
                        "getLocation"
                      ]
                })
                wx.ready(function(){
                    alert(1); 
                });
                wx.error(function(res){
                    console.log(res);
                    alert(2);
                })
        }
    })
})

the above method is successful, you can get the longitude and latitude of the user, my problem now is that I can not get the value of that code in the same php file, I can only access a new php file, but for a new file, the code value is there, always prompting that signature is invalid, I think there should be something wrong with the top 6 posted by me, but I haven"t understood the meaning after reading it for a long time! Is there a great god who can talk about a process that Wechat handed over to us? we provided Wechat with a series of parameters Wechat checked and then sent the user"s longitude and latitude to us? Where should I send it? What kind of parameters or what will it bring? Could you explain in detail what I posted on the top?

Apr.23,2021

or whether there is a boss who knows whether the url in the generated signature parameter can be added to the parameter

.
Menu