php卡券营销源代码_[PHP+JS]卡券(潦草笔记,全代
码,亲测通过)
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好看主页源码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模式创建卡券
// 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'],
'mmbiz.qpic/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o
'餐厅',
'132元双⼈⽕锅套餐',
'020-********',
'不可与其他优惠同享\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'],
//
'mmbiz.qpic/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zH
// '餐厅',
// '020-********',
// '不可与其他优惠同享\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'],
//
'mmbiz.qpic/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zH
// '餐厅',
// '132元双⼈⽕锅套餐',
/
/ '020-********',
// '不可与其他优惠同享\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'],
//
'mmbiz.qpic/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zH
// '餐厅',
// '132元双⼈⽕锅套餐',
// '020-********',
// '不可与其他优惠同享\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'],
/
/
'mmbiz.qpic/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zH
// '餐厅',
// '132元双⼈⽕锅套餐',
// '020-********',
// '不可与其他优惠同享\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));
}
// ========================================
// 需要客户领取后才能有数据
$result = WxPublic_Card_UserCardList($publicToken['access_token'], $openId, $cardIdList[count($cardIdList) - 1]);
echo 'UserCardList' . PHP_EOL;
print_r($result);
// 需要客户领取后才能查询
$result = WxPublic_Card_CodeGet($publicToken['access_token'], $cardIdList[count($cardIdList) - 1], $codes[0]);
echo 'CodeGet' . PHP_EOL;
print_r($result);
if($result['errcode'] == '0' && $result['can_consume'] == true) {
// 需要客户领取后才能核销
$result = WxPublic_Card_CodeConsume($publicToken['access_token'], $cardIdList[count($cardIdList) - 1], $codes[0]);
echo 'CodeConsume' . PHP_EOL;
print_r($result);
}
// ========================================
for($i = 0; $i < count($cardIdList);++$i) {
for($j = 0; $j < count($codes);++$j) {
// 需要客户领取后才能失效,已使⽤的不能失效
$result = WxPublic_Card_CodeUnavailable($publicToken['access_token'], $cardIdList[$i], $codes[$j], '⽤户发⽣退款');
echo 'Unavailable:' . $cardIdList[$i] . '-' . $codes[$j] . PHP_EOL;
print_r($result);
}
$result = WxPublic_Card_Delete($publicToken['access_token'], $cardIdList[$i]);
echo 'Delete:' . $cardIdList[$i] . PHP_EOL;
print_r($result);
}
$result = WxPublic_Card_BizuinInfo($publicToken['access_token'], date('Y-m-d', strtotime('-62 day')), date('Y-m-d',
strtotime('-1 day')), 0);
echo 'BizuinInfo-0' . PHP_EOL;
print_r($result);
$result = WxPublic_Card_BizuinInfo($publicToken['access_token'], date('Y-m-d', strtotime('-62 day')), date('Y-m-d',
strtotime('-1 day')), 1);
echo 'BizuinInfo-1' . PHP_EOL;
print_r($result);*/}echo '
';
template('pad/test');exit();
}elseif($do == 'wx_authority_signature') {$publicToken = WxPublic_AccessToken(APPID,SECRET);if($publicToken != null && $publicToken['expires_datetime'] >= time()) {exit(json_encode(Wx_AuthoritySignature($publicToken, $_GPC['url'])));
}exit();
$publicToken = WxPublic_AccessToken(APPID,SECRET);if($publicToken != null && $publicToken['expires_datetime'] >=
time()) {$result = WxPublic_Card_BatchGet($publicToken['access_token']);if($result['errcode'] == '0') {$codes = array();for($i = 1; $i <= 5; ++$i) {$codes[] = strval(10000 + $i);
}$data = array();foreach ($result['card_id_list'] as $cardId) {for($i = 0; $i < count($codes); ++$i) {$signature =
Wx_CardSignature($publicToken['access_token'], $cardId);$data[] = array('api_ticket' => $signature['api_ticket'],
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论