Browse Source

add signature

stanley-king 7 years atrás
parent
commit
3cbc98649c

+ 5 - 5
helper/third_author/signaturer.php

@@ -36,7 +36,7 @@ class signaturer
         $this->mData = [];
     }
 
-    public function signurl()
+    public function signurl($sign_url)
     {
         $ticket = $this->jsapi_ticket();
         if($ticket == false) {
@@ -44,19 +44,19 @@ class signaturer
             return false;
         }
 
-        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
-        $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
+//        $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->noncestr();
-        $string = "jsapi_ticket={$ticket}&noncestr={$nonceStr}&timestamp={$timestamp}&url=$url";
+        $string = "jsapi_ticket={$ticket}&noncestr={$nonceStr}&timestamp={$timestamp}&url={$sign_url}";
         $signature = sha1($string);
 
         $sign = array(
             "appid"     => signaturer::appid,
             "noncestr"  => $nonceStr,
             "timestamp" => $timestamp,
-            "url"       => $url,
+            "url"       => $sign_url,
             "signature" => $signature,
             "rawstring" => $string
         );

+ 5 - 1
mobile/control/mshop.php

@@ -122,7 +122,11 @@ class mshopControl extends specialControl
 
     public function signurlOp()
     {
-        $result = thrid_author\signaturer::instance()->signurl();
+        $sign_url = urldecode($_GET['sign_url']);
+        if(empty($sign_url)) {
+            return self::outerr(errcode::ErrParamter);
+        }
+        $result = thrid_author\signaturer::instance()->signurl($sign_url);
         if($result == false) {
             return self::outerr(errcode::ErrAuthor);
         } else {

+ 6 - 3
mobile/templates/default/signature.php

@@ -16,15 +16,18 @@
 <script type="text/javascript">
     $(function ()
     {
+        var  sign_url = "http://p.lrlz.com/mobile/index.php?act=mshop&op=test&client_type=wap";
+        sign_url = encodeURIComponent(sign_url);
         $.ajax({
             type: "get",
             async: false,
-            url: "http://"+ window.location.host +"/mobile/index.php?act=mshop&op=signurl&client_type=ajax",
+            url: "http://"+ window.location.host +"/mobile/index.php?act=mshop&op=signurl&client_type=ajax&sign_url=" + sign_url,
             dataType: "jsonp",
             jsonp: "callback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)
             success: function (json) {
                 console.log(json);
                 var jsonx = json.datas;
+
                 var timestamp = jsonx.timestamp,
                     nonceStr = jsonx.noncestr,
                     signature = jsonx.signature,
@@ -81,8 +84,8 @@
                 wx.onMenuShareAppMessage({
                     title: "分享测试", // 分享标
                     desc: "分享测试分享测试",
-                    link: "http://www.baidu.com",    //cookie读取
-                    imgUrl: "http://pic.58pic.com/58pic/14/27/45/71r58PICmDM_1024.jpg",// 分享图标
+                    link: "http://p.lrlz.com/mobile/index.php?act=mshop&op=test&client_type=wap",    //cookie读取
+                    imgUrl: "http://p.lrlz.com/data/upload/shop/store/goods/6/6_05511819175096982_360.jpg",// 分享图标
                     trigger: function (res) {
                         // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
                     },