@@ -18,7 +18,7 @@ class WechatScript extends Common {
1818 * JSAPI授权TICKET
1919 * @var string
2020 */
21- private $ jsapi_ticket ;
21+ public $ jsapi_ticket ;
2222
2323 /**
2424 * 删除JSAPI授权TICKET
@@ -36,11 +36,15 @@ public function resetJsTicket($appid = '') {
3636 * 获取JSAPI授权TICKET
3737 * @param string $appid 用于多个appid时使用,可空
3838 * @param string $jsapi_ticket 手动指定jsapi_ticket,非必要情况不建议用
39+ * @param string $access_token 获取 jsapi_ticket 指定 access_token
3940 * @return bool|string
4041 */
41- public function getJsTicket ($ appid = '' , $ jsapi_ticket = '' ) {
42- if (!$ this ->access_token && !$ this ->getAccessToken ()) {
43- return false ;
42+ public function getJsTicket ($ appid = '' , $ jsapi_ticket = '' , $ access_token = '' ) {
43+ if (empty ($ access_token )) {
44+ if (!$ this ->access_token && !$ this ->getAccessToken ()) {
45+ return false ;
46+ }
47+ $ access_token = $ this ->access_token ;
4448 }
4549 if (empty ($ appid )) {
4650 $ appid = $ this ->appid ;
@@ -61,7 +65,7 @@ public function getJsTicket($appid = '', $jsapi_ticket = '') {
6165 return $ this ->jsapi_ticket = call_user_func_array (Loader::$ callback [__FUNCTION__ ], array (&$ this , &$ cache ));
6266 }
6367 # 调接口获取
64- $ result = Tools::httpGet (self ::API_URL_PREFIX . self ::GET_TICKET_URL . "access_token= {$ this -> access_token }" . '&type=jsapi ' );
68+ $ result = Tools::httpGet (self ::API_URL_PREFIX . self ::GET_TICKET_URL . "access_token= {$ access_token }" . '&type=jsapi ' );
6569 if ($ result ) {
6670 $ json = json_decode ($ result , true );
6771 if (!$ json || !empty ($ json ['errcode ' ])) {
@@ -82,10 +86,11 @@ public function getJsTicket($appid = '', $jsapi_ticket = '') {
8286 * @param int $timestamp 当前时间戳 (为空则自动生成)
8387 * @param string $noncestr 随机串 (为空则自动生成)
8488 * @param string $appid 用于多个appid时使用,可空
85- * @return bool|array 返回签名字串
89+ * @param string $access_token 获取 jsapi_ticket 指定 access_token
90+ * @return array|bool 返回签名字串
8691 */
87- public function getJsSign ($ url , $ timestamp = 0 , $ noncestr = '' , $ appid = '' ) {
88- if (!$ this ->jsapi_ticket && !$ this ->getJsTicket ($ appid ) || empty ($ url )) {
92+ public function getJsSign ($ url , $ timestamp = 0 , $ noncestr = '' , $ appid = '' , $ access_token = '' ) {
93+ if (!$ this ->jsapi_ticket && !$ this ->getJsTicket ($ appid, '' , $ access_token ) || empty ($ url )) {
8994 return false ;
9095 }
9196 $ data = array (
@@ -95,7 +100,8 @@ public function getJsSign($url, $timestamp = 0, $noncestr = '', $appid = '') {
95100 "url " => trim ($ url ),
96101 );
97102 return array (
98- # 'debug' => true,
103+ "url " => $ url ,
104+ 'debug ' => false ,
99105 "appId " => empty ($ appid ) ? $ this ->appid : $ appid ,
100106 "nonceStr " => $ data ['noncestr ' ],
101107 "timestamp " => $ data ['timestamp ' ],
0 commit comments