Browse Source

测试代码

chenbo 4 years ago
parent
commit
d545f8959a
4 changed files with 14 additions and 14 deletions
  1. 4 4
      api/demo/wxinfo.html
  2. 2 2
      api/wxinfo.php
  3. 1 1
      front-page/fission-page.html
  4. 7 7
      lib/common/weixin_public.class.php

+ 4 - 4
api/demo/wxinfo.html

@@ -19,7 +19,7 @@
                 var timestamp =$('input[name="timestamp"]').val();
                 var sign = $.md5(method+timestamp);
                 var code = $('input[name="code"]').val();
-                var url = $('input[name="url"]').val();
+                var jsUrl = $('input[name="jsUrl"]').val();
 
                 $('#sign').val(sign);
                 $.ajax({
@@ -29,7 +29,7 @@
                         timestamp :timestamp,
                         sign   : sign,
                         code   : code,
-                        url    : url,
+                        jsUrl    : jsUrl,
                     },
                     url : "../api.php",
                     beforeSend :  function(data){
@@ -70,8 +70,8 @@
                 <input type="text" class="input-text"  name="code" value=""/>
             </p>
             <p>
-                <span>url:</span>
-                <input type="text" class="input-text"  name="url" value=""/>
+                <span>jsUrl:</span>
+                <input type="text" class="input-text"  name="jsUrl" value=""/>
             </p>
 
             <p><button class="button success small" id="btn" type="button">发送请求</button></p>

+ 2 - 2
api/wxinfo.php

@@ -7,9 +7,9 @@
  */
 try {
     $code = safeCheck($_POST["code"], 0);
-    $url = safeCheck($_POST["url"], 0);
+    $jsUrl = safeCheck($_POST["jsUrl"], 0);
     $weixin_public = new weixin_public(APPID, APPSECRET, APPURI);
-    $info = $weixin_public->getAllInfo($code, $url);
+    $info = $weixin_public->getAllInfo($code, $jsUrl);
     echo action_msg($info, 200);
 
 } catch (MyException $e) {

+ 1 - 1
front-page/fission-page.html

@@ -126,7 +126,7 @@
                         method: 'wxinfo',
                         timestamp: 11111111,
                         code:that.weChatCode,
-                        url:'http://www.baidu.com',//(location.href.split('#')[0]),
+                        jsUrl:'http://www.baidu.com',//(location.href.split('#')[0]),
                         sign:md5('wxinfo'+'11111111')
                     }, //代表传过去的参数对象,
                     transformRequest: [function(data) {

+ 7 - 7
lib/common/weixin_public.class.php

@@ -76,16 +76,16 @@ class weixin_public
         return $str;
     }
 
-    private function getSignPackage($jsToken, $url) {
+    private function getSignPackage($jsToken, $jsUrl) {
         // 注意 URL 一定要动态获取,不能 hardcode.
         $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
-        //$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
-        //$url = "$protocol$_SERVER[HTTP_HOST]/front-page/fission-page.html";
+        //$jsUrl = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
+        //$jsUrl = "$protocol$_SERVER[HTTP_HOST]/front-page/fission-page.html";
 
         $nonceStr = self::createNonceStr();
         $timestamp = time();
         // 这里参数的顺序要按照 key 值 ASCII 码升序排序
-        $string = "jsapi_ticket=$jsToken&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
+        $string = "jsapi_ticket=$jsToken&noncestr=$nonceStr&timestamp=$timestamp&url=$jsUrl";
 
         $signature = sha1($string);
 
@@ -93,7 +93,7 @@ class weixin_public
             "appId"     => $this->appid,
             "nonceStr"  => $nonceStr,
             "timestamp" => $timestamp,
-            "url"       => $url,
+            "url"       => $jsUrl,
             "signature" => $signature,
             "rawString" => $string
         );
@@ -101,7 +101,7 @@ class weixin_public
         return $signPackage;
     }
 
-    public function getAllInfo($code, $url)
+    public function getAllInfo($code, $jsUrl)
     {
         $reader = array();
 
@@ -142,7 +142,7 @@ class weixin_public
             return $jsTokenInfo;
         }
 
-        $signPackage = self::getSignPackage($jsTokenInfo['ticket'], $url);
+        $signPackage = self::getSignPackage($jsTokenInfo['ticket'], $jsUrl);
         $reader['js_sign'] = $signPackage;
 
         return $reader;