一,官方文档说明入口
https://opendocs.alipay.com/open/282/105996
二,红包说明
前期准备不再缀述,就是设置公钥(最好采用证书模式)这样即支持现金红包,又可以支持活动红包。
三,活动红包具体步骤
前期准备,应用申请及开放平台设置(关键是 公钥证书 设置)
App<==>后端(php)授权串(支付宝登录授权完成版)/或者不采用授权模式使用用户支付宝帐号
App->授权后拿到支付宝唯一标识uid/或者支付宝帐号->后端php( alipay.marketing.campaign.cash.trigger )
四,步骤说明
如果长期做活动红包,基本业务后台要维护一份红包列表,要监控每一个活动红包的领取情况,余额等
1,创建红包:alipay.marketing.campaign.cash.create 可以根据自身业务创建随机红包或者固定面额红包。
vendor('alipay2.AopCertClient');
$aop = new AopCertClient;
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $app_id;
$aop->rsaPrivateKey = $aliConf['rsaPrivateKey'];
$aop->alipayrsaPublicKey = $aliConf['rsaPublicKey'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'UTF-8';
$aop->format = 'json';
$aop->appCertSN = $aop->getCertSN($aliConf['alipayrsaAppPath']); //支付宝应用证书
$aop->alipayRootCertSN = $aop->getRootCertSN($aliConf['alipayrsaRootPath']); //根证书sn
vendor('alipay2.request.AlipayMarketingCampaignCashCreateRequest');
$request = new AlipayMarketingCampaignCashCreateRequest ();
$request->setBizContent("{" .
""coupon_name":"$coupon_name"," .
""prize_type":"$prize_type"," .
""total_money":"$total_money"," .
""total_num":"$total_num"," .
""prize_msg":"$prize_msg"," .
""start_time":"$activity_start_time"," .
""end_time":"$activity_end_time"," .
""merchant_link":"$merchant_link"," .
""send_freqency":"$send_freqency"" .
" }");
$result = $aop->execute ( $request);
返回:
{
"alipay_marketing_campaign_cash_create_response": {
"code": "10000",
"msg": "Success",
"crowd_no": "EPOJZsBg3A-CZOJE4qlbAueA7By4oJLDwEeYZlAiAnbMnSZ96O-zxUfKlHp5cxmx",
"pay_url": "http%3a%2f%2fcashier.stable.alipay.net%2fstandard%2flightpay%2flightPayCashier.htm%3forderId%3d0826e2e3984d6fa7b92046.rz0NN4263%",
"origin_crowd_no": "20160901109410190092922300444004"
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}
返回有活动红包的支付连接,24小时有效,支付完等待红包状态变为READY状态即可。(活动状态,CREATED: 已创建未打款;PAID:已打款;READY:活动已开始;PAUSE:活动已暂停;CLOSED:活动已结束;SETTLE:活动已清算)
2,发放红包
//红包下单参数
$aliParam = [
'login_id' => $identity, //支付宝帐号
'crowd_no' => $find['crowd_no'],
'order_price' => $price*100, //订单金额 单位分
'out_biz_no' => $out_biz_no, //订单号
];
vendor('alipay2.AopCertClient');
$aop = new AopCertClient;
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $app_id;
$aop->rsaPrivateKey = $aliConf['rsaPrivateKey'];
$aop->alipayrsaPublicKey = $aliConf['rsaPublicKey'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'UTF-8';
$aop->format = 'json';
$aop->appCertSN = $aop->getCertSN($aliConf['alipayrsaAppPath']); //支付宝应用证书
$aop->alipayRootCertSN = $aop->getRootCertSN($aliConf['alipayrsaRootPath']); //根证书sn
//支付宝营销红包
vendor('alipay2.request.AlipayMarketingCampaignCashTriggerRequest');
$request = new AlipayMarketingCampaignCashTriggerRequest();
$request->setBizContent(json_encode($aliParam));
$aliResult = $aop->execute ( $request);
返回:
{
"alipay_marketing_campaign_cash_trigger_response": {
"code": "10000",
"msg": "Success",
"trigger_result": "true",
"prize_amount": "234.40",
"repeat_trigger_flag": "true或false",
"partner_id": "2088123456789012",
"error_msg": "用户实名验证不通过",
"coupon_name": "***周年庆红包",
"prize_msg": "XXX送您大红包,祝您中秋快乐",
"merchant_logo": "http://tfs.alipay.com/images/partner/1111111xxxxxxx_160x160",
"biz_no": "20170117110070001502640004976114",
"out_biz_no": "2017021319450001"
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}
3,查看活动红包详情
alipay.marketing.campaign.cash.detail.query
4,修改活动红包状态
alipay.marketing.campaign.cash.status.modify
如果实现了支付宝的现金红包,活动红包,基本可以满足业务不同场景的不同的需求了,例如不同渠道使用不同主体,不同渠道使用不同方式等等。