卡券(WxCard)

微信参考文档

https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141229

前提条件

  1. 接入公众号需要已获得微信卡券相关权限;

卡券类型

  1. 优惠券 \wii\weixin\card\WxCouponCard

常用方法

获取卡券扩展字段

\wii\weixin\card\WxCouponCard::getCardExt($code = '', $openId = '', $outerStr = '')

参数说明

参数 类型 必须 说明
code string 指定的卡券code码
openId string 指定领取者的openid
outerStr string 领取渠道参数,用于标识本次领取的渠道值

使用实例

// 从项目全局 \Wii::app()->wxPubAccount 对象中获取
$wxPubAccount = \Wii::app()->wxPubAccount;

// 从 \wii\weixin\pubAccount\WxPubAccount 类中获取
// $wxPubAccount = \wii\weixin\pubAccount\WxPubAccount::instance('wxa40da3f0ba5d2339');

// 优惠券
$openId = \Wii::app()->user->getUin();
$cardList = [];
$couponCardId = 'pnqj0jorFPnUB1QDlFTCGdlXx5d4';
$couponCardCode = time();
$outerStr = 'sample';

$couponCard = WxCouponCard::instance(\Wii::app()->wxPubAccount);
$couponCard->cardId = $couponCardId;
$couponCardConfig = $couponCard->getConfig($couponCardCode, $openId, $outerStr);
$cardList[] = $couponCardConfig;

// 构造JsConfig
$this->jsConfig([
    'wx' => [
        'cardList' => $cardList,
        'config' => [
            'debug' => true,
            'jsApiList' => [
                'addCard'
            ]
        ]
    ]
], true);

返回数据

{
  "timestamp": "1502809866",
  "nonce_str": "Nwr7GPlmlucWZa22lE8UoXoKxjdAs9QP",
  "signature": "2827a35b153cb8e7194b033012de60488e56b3d6"
}

results matching ""

    No results matching ""