Skip to content

Commit

Permalink
[更新]调整数据处理函数,兼容PHP7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujingli committed Jan 16, 2018
1 parent 7551bad commit 390beea
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions Wechat/WechatCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getJsCardTicket($appid = '', $jsapi_ticket = '')
if (($jsapi_ticket = Tools::getCache($authname))) {
return $jsapi_ticket;
}
$result = Tools::httpGet(self::API_URL_PREFIX . self::GET_TICKET_URL . "access_token={$this->access_token}" . '&type=wx_card');
$result = Tools::httpGet(self::API_URL_PREFIX . self::GET_TICKET_URL . "access_token={$this->access_token}&type=wx_card");
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
Expand Down Expand Up @@ -125,30 +125,35 @@ public function createChooseCardJsPackage($cardid = null, $cardtype = null, $sho
*/
public function createAddCardJsPackage($cardid = null, $data = array())
{

function _sign($cardid = null, $attr = array(), $self)
{
unset($attr['outer_id']);
$attr['cardId'] = $cardid;
$attr['timestamp'] = time();
$attr['api_ticket'] = $self->getJsCardTicket();
$attr['nonce_str'] = Tools::createNoncestr();
$attr['signature'] = $self->getTicketSignature($attr);
unset($attr['api_ticket']);
return $attr;
}

$cardList = array();
if (is_array($cardid)) {
foreach ($cardid as $id) {
$cardList[] = array('cardId' => $id, 'cardExt' => json_encode(_sign($id, $data, $this)));
$cardList[] = array('cardId' => $id, 'cardExt' => json_encode($this->_cardSign($id, $data)));
}
} else {
$cardList[] = array('cardId' => $cardid, 'cardExt' => json_encode(_sign($cardid, $data, $this)));
$cardList[] = array('cardId' => $cardid, 'cardExt' => json_encode($this->_cardSign($cardid, $data)));
}
return array('cardList' => $cardList);
}

/**
* 卡券数据签名
* @param null|string $cardid
* @param array $attr
* @return array
*/
private function _cardSign($cardid = null, $attr = array())
{
unset($attr['outer_id']);
$attr['cardId'] = $cardid;
$attr['timestamp'] = time();
$attr['api_ticket'] = $this->getJsCardTicket();
$attr['nonce_str'] = Tools::createNoncestr();
$attr['signature'] = $this->getTicketSignature($attr);
unset($attr['api_ticket']);
return $attr;
}

/**
* 获取微信卡券签名
* @param array $arrdata 签名数组
Expand Down

0 comments on commit 390beea

Please sign in to comment.