Skip to content

Commit 390beea

Browse files
committed
[更新]调整数据处理函数,兼容PHP7.2
1 parent 7551bad commit 390beea

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Wechat/WechatCard.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function getJsCardTicket($appid = '', $jsapi_ticket = '')
7979
if (($jsapi_ticket = Tools::getCache($authname))) {
8080
return $jsapi_ticket;
8181
}
82-
$result = Tools::httpGet(self::API_URL_PREFIX . self::GET_TICKET_URL . "access_token={$this->access_token}" . '&type=wx_card');
82+
$result = Tools::httpGet(self::API_URL_PREFIX . self::GET_TICKET_URL . "access_token={$this->access_token}&type=wx_card");
8383
if ($result) {
8484
$json = json_decode($result, true);
8585
if (empty($json) || !empty($json['errcode'])) {
@@ -125,30 +125,35 @@ public function createChooseCardJsPackage($cardid = null, $cardtype = null, $sho
125125
*/
126126
public function createAddCardJsPackage($cardid = null, $data = array())
127127
{
128-
129-
function _sign($cardid = null, $attr = array(), $self)
130-
{
131-
unset($attr['outer_id']);
132-
$attr['cardId'] = $cardid;
133-
$attr['timestamp'] = time();
134-
$attr['api_ticket'] = $self->getJsCardTicket();
135-
$attr['nonce_str'] = Tools::createNoncestr();
136-
$attr['signature'] = $self->getTicketSignature($attr);
137-
unset($attr['api_ticket']);
138-
return $attr;
139-
}
140-
141128
$cardList = array();
142129
if (is_array($cardid)) {
143130
foreach ($cardid as $id) {
144-
$cardList[] = array('cardId' => $id, 'cardExt' => json_encode(_sign($id, $data, $this)));
131+
$cardList[] = array('cardId' => $id, 'cardExt' => json_encode($this->_cardSign($id, $data)));
145132
}
146133
} else {
147-
$cardList[] = array('cardId' => $cardid, 'cardExt' => json_encode(_sign($cardid, $data, $this)));
134+
$cardList[] = array('cardId' => $cardid, 'cardExt' => json_encode($this->_cardSign($cardid, $data)));
148135
}
149136
return array('cardList' => $cardList);
150137
}
151138

139+
/**
140+
* 卡券数据签名
141+
* @param null|string $cardid
142+
* @param array $attr
143+
* @return array
144+
*/
145+
private function _cardSign($cardid = null, $attr = array())
146+
{
147+
unset($attr['outer_id']);
148+
$attr['cardId'] = $cardid;
149+
$attr['timestamp'] = time();
150+
$attr['api_ticket'] = $this->getJsCardTicket();
151+
$attr['nonce_str'] = Tools::createNoncestr();
152+
$attr['signature'] = $this->getTicketSignature($attr);
153+
unset($attr['api_ticket']);
154+
return $attr;
155+
}
156+
152157
/**
153158
* 获取微信卡券签名
154159
* @param array $arrdata 签名数组

0 commit comments

Comments
 (0)