Showing
3 changed files
with
6 additions
and
6 deletions
@@ -45,7 +45,7 @@ class Controller_Default extends Controller_Abstract | @@ -45,7 +45,7 @@ class Controller_Default extends Controller_Abstract | ||
45 | public function testAction() | 45 | public function testAction() |
46 | { | 46 | { |
47 | $link = SITE_MAIN.url('default/test'); | 47 | $link = SITE_MAIN.url('default/test'); |
48 | - $this->_view['wechat'] = Lib_Wechat_JSSDK::getSignPackage($link); | 48 | + $this->_view['wechat'] = Lib_Wechat_JSSDK::getSignPackage(); |
49 | } | 49 | } |
50 | public function contactusAction() | 50 | public function contactusAction() |
51 | { | 51 | { |
@@ -3,13 +3,14 @@ class Lib_Wechat_JSSDK { | @@ -3,13 +3,14 @@ class Lib_Wechat_JSSDK { | ||
3 | public static $appId = YOHO_WECHAT_APPID; | 3 | public static $appId = YOHO_WECHAT_APPID; |
4 | public static $appSecret = YOHO_WECHAT_APPSECRET; | 4 | public static $appSecret = YOHO_WECHAT_APPSECRET; |
5 | 5 | ||
6 | - public static function getSignPackage($url = '') | 6 | + public static function getSignPackage() |
7 | { | 7 | { |
8 | $jsapiTicket = self::getJsApiTicket(); | 8 | $jsapiTicket = self::getJsApiTicket(); |
9 | 9 | ||
10 | // 注意 URL 一定要动态获取,不能 hardcode. | 10 | // 注意 URL 一定要动态获取,不能 hardcode. |
11 | - /* $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; | ||
12 | - $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; */ | 11 | + $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; |
12 | + $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; | ||
13 | + echo $url; | ||
13 | // 确保你获取用来签名的url是动态获取的,动态页面可参见实例代码中php的实现方式。如果是html的静态页面在前端通过ajax将url传到后台签名,前端需要用js获取当前页面除去'#'hash部分的链接(可用location.href.split('#')[0]获取),因为页面一旦分享,微信客户端会在你的链接末尾加入其它参数,如果不是动态获取当前链接,将导致分享后的页面签名失败。 | 14 | // 确保你获取用来签名的url是动态获取的,动态页面可参见实例代码中php的实现方式。如果是html的静态页面在前端通过ajax将url传到后台签名,前端需要用js获取当前页面除去'#'hash部分的链接(可用location.href.split('#')[0]获取),因为页面一旦分享,微信客户端会在你的链接末尾加入其它参数,如果不是动态获取当前链接,将导致分享后的页面签名失败。 |
14 | $timestamp = time(); | 15 | $timestamp = time(); |
15 | $nonceStr = self::createNonceStr(); | 16 | $nonceStr = self::createNonceStr(); |
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | </head> | 11 | </head> |
12 | <body> | 12 | <body> |
13 | test | 13 | test |
14 | - | 14 | +</body> |
15 | <script type="text/javascript" charset="utf-8" src="http://staticzine.myoho.net/download/jquery.min.js?v=20150429"></script> | 15 | <script type="text/javascript" charset="utf-8" src="http://staticzine.myoho.net/download/jquery.min.js?v=20150429"></script> |
16 | <script type="text/javascript" charset="utf-8" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> | 16 | <script type="text/javascript" charset="utf-8" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> |
17 | <script type="text/javascript"> | 17 | <script type="text/javascript"> |
@@ -55,5 +55,4 @@ wx.error(function (res) { | @@ -55,5 +55,4 @@ wx.error(function (res) { | ||
55 | alert(res.errMsg); | 55 | alert(res.errMsg); |
56 | }); | 56 | }); |
57 | </script> | 57 | </script> |
58 | -</body> | ||
59 | </html> | 58 | </html> |
-
Please register or login to post a comment