define('APPID', 'xxxxxxxxxxxxxxxx');define('SECRET', 'xxxxxxxxxxxxxxxx');$publicToken = null;if($do == 'test') {set_time_limit(0);$openId = 'xxxxxxxxxxxxxxxx';//$account = account_fetch($_W['acid']);
//$account['key'], $account['secret']
echo '
';$publicToken = WxPublic_AccessToken(APPID,SECRET);echo 'AccessToken' . PHP_EOL;print_r($publicToken);if($publicToken != null && $publicToken['expires_datetime'] >= time()) {//创建前获取公众号的全部卡券
$result = WxPublic_Card_BatchGet($publicToken['access_token']);echo 'BatchGet' . PHP_EOL;print_r($result);if($result['errcode'] == '0') {$cardIdList = $result['card_id_list'];$codes = array();for($i = 1; $i <= 5; $i++) {$codes[] = strval(10000 + $i);
}foreach($cardIdList as $cardId) {$result = WxPublic_Card_Get($publicToken['access_token'], $cardId);echo 'Get' . PHP_EOL;print_r($result);$result = WxPublic_Card_CheckCode($publicToken['access_token'], $cardId, $codes);echo 'CheckCode' . PHP_EOL;print_r($result);
}$result = WxPublic_Card_CardInfo($publicToken['access_token'], date('Y-m-d', strtotime('-62 day')), date('Y-m-d', strtotime('-1 day')), 0);echo 'CardInfo-0' . PHP_EOL;print_r($result);$result = WxPublic_Card_CardInfo($publicToken['access_token'], date('Y-m-d', strtotime('-62 day')), date('Y-m-d', strtotime('-1 day')), 1);echo 'CardInfo-1' . PHP_EOL;print_r($result);
}/*// ========================================
$aPath = realpath(dirname(__FILE__) . './test.jpg');
$cardImage = WxPublic_Card_Uploadimg($publicToken['access_token'], $aPath);
//if($cardImage !== null && isset($cardImage['url'])) {
echo 'Uploadimg' . PHP_EOL;
print_r($cardImage);
//}
// ========================================
// 使用GET_CUSTOM_CODE_MODE_DEPOSIT模式创建卡券
// 用法参考:https://blog.csdn.net/u011738153/article/details/50457167
// 1.quantity初始值设置为0,设置use_custom_code=true,get_custom_code_mode='GET_CUSTOM_CODE_MODE_DEPOSIT'
// 2.审核后添加code
// 3.修改库存,<= code数量
$card = WxPublic_Card_Create_Groupon(
$publicToken['access_token'],
'http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0',
'微信餐厅',
'132元双人火锅套餐',
'020-88888888',
'不可与其他优惠同享\r\n如需团购券发票,请在消费时向商户提出\r\n店内均可使用,仅限堂食',
date('Y-m-d', strtotime('-1 day')),
date('Y-m-d', strtotime('+1 year')),
'以下锅底2选1(有菌王锅、麻辣锅、大骨锅、番茄锅、清补 凉锅、酸菜鱼锅可选):\n大锅1份 12元\n小锅2份 16元',
2
);
// $card = WxPublic_Card_Create_Cash(
// $publicToken['access_token'],
// 'http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0',
// '微信餐厅',
// '020-88888888',
// '不可与其他优惠同享\r\n如需团购券发票,请在消费时向商户提出\r\n店内均可使用,仅限堂食',
// date('Y-m-d', strtotime('-1 day')),
// date('Y-m-d', strtotime('+1 year')),
// 1000,
// 10000,
// 2
// );
// $card = WxPublic_Card_Create_Discount(
// $publicToken['access_token'],
// 'http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0',
// '微信餐厅',
// '132元双人火锅套餐',
// '020-88888888',
// '不可与其他优惠同享\r\n如需团购券发票,请在消费时向商户提出\r\n店内均可使用,仅限堂食',
// date('Y-m-d', strtotime('-1 day')),
// date('Y-m-d', strtotime('+1 year')),
// 30,
// 2
// );
// $card = WxPublic_Card_Create_Gift(
// $publicToken['access_token'],
// 'http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0',
// '微信餐厅',
// '132元双人火锅套餐',
// '020-88888888',
// '不可与其他优惠同享\r\n如需团购券发票,请在消费时向商户提出\r\n店内均可使用,仅限堂食',
// date('Y-m-d', strtotime('-1 day')),
// date('Y-m-d', strtotime('+1 year')),
// '可兑换音乐木盒一个',
// 2
// );
// $card = WxPublic_Card_Create_GeneralCoupon(
// $publicToken['access_token'],
// 'http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0',
// '微信餐厅',
// '132元双人火锅套餐',
// '020-88888888',
// '不可与其他优惠同享\r\n如需团购券发票,请在消费时向商户提出\r\n店内均可使用,仅限堂食',
// date('Y-m-d', strtotime('-1 day')),
// date('Y-m-d', strtotime('+1 year')),
// '优惠券专用,填写优惠详情',
// 2
// );
echo 'Create' . PHP_EOL;
print_r($card);
if($card['errcode'] == '0' && isset($card['card_id'])) {
$codes = array();
for($i = 1; $i <= 5; $i++) {
$codes[] = strval(10000 + $i);
}
if(count($codes) > 0) {
$codeResult = WxPublic_Card_AddCode($publicToken['access_token'], $card['card_id'], $codes);
if($codeResult['errcode'] == '0') {
$countResult = WxPublic_Card_CodeCount($publicToken['access_token'], $card['card_id']);
if($countResult['errcode'] == '0' && intval($countResult['count']) > 0)
WxPublic_Card_ModifyStock($publicToken['access_token'], $card['card_id'], intval($countResult['count']));
else
throw new Exception('卡券修改库存失败:' . json_encode($countResult));
} else {
throw new Exception('卡券添加code失败:' . json_encode($codeResult));
}
}
// 失败
// $result = WxPublic_Card_CodeUpdate($publicToken['access_token'], $codes[count($codes) - 1], '99999', $cardIdList[count($cardIdList) - 1]);
// echo 'CodeUpdate' . PHP_EOL;
// print_r($result);
$result = WxPublic_Card_CheckCode($publicToken['access_token'], $cardIdList[count($cardIdList) - 1], $codes);
echo 'CheckCode' . PHP_EOL;
print_r($result);
$result = WxPublic_Card_Get($publicToken['access_token'], $card['card_id']);
echo 'Get' . PHP_EOL;
print_r($result);
$result = WxPublic_Card_QrcodeCreate($publicToken['access_token'], $card['card_id']);
echo 'QrcodeCreate' . PHP_EOL;
print_r($result);
} else {
throw new Exception('创建卡券失败:' . json_encode($card));
}
// =