首页 > 上网技巧 > 电脑小技巧 > PHP微信小程序addCard签名

PHP微信小程序addCard签名

时间:2018-06-18 16:06 作者:QQ地带 我要评论

$app = Factory::officialAccount([
    'app_id' => config('app_id'),
    'secret' => config('secret')
]);
$this->card = $app->card;
 
 获取 tTicket
public function getTicket() {
    $ret = $this->card->httpGet('/cgi-bin/ticket/getticket', ['type'=>"wx_card"]);
    return $ret;
}
 
/**
 *  卡券签名
 *
 * 2018/6/13
 *
 * @author XiaoBing <xiaobingby@qq.com>
 */
public function cardSignature($card_id, $api_ticket) {
    $time = time();
    $nonce_str = time()+1;
    $data = array($time, $nonce_str, $card_id, $api_ticket);
    asort($data, SORT_STRING); // 排序
    $key = implode($data); // 加密
    $signature = sha1($key);
    return ['signature'=>$signature, 'timestamp'=>$time, 'nonce_str'=>$nonce_str, 'card_id'=>$card_id, 'api_ticket'=>$api_ticket];
}

标签: 微信
顶一下
(0)
0%
踩一下
(0)
0%

Google提供的广告