营销活动送红包注意事项:[url]https://openclub.alipay.com/read.php?tid=12196&fid=71[/url]
一、PHP示例demo
PHP版demo:download:营销活动送红包PHP版.zip
二、调用接口
1、创建现金活动接口请求示例
appId = '填写你的沙箱appid';$aop->rsaPrivateKey = '填写您的原始私钥';$aop->alipayrsaPublicKey='填写您的支付宝公钥';$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';$aop->apiVersion = '1.0';$aop->signType = 'RSA2';$aop->postCharset='UTF-8';$aop->format='json';$request = new AlipayMarketingCampaignCashCreateRequest ();$request->setBizContent("{" . "\"coupon_name\":\"煜雨创建营销活动送红包php\"," . //prize_type现金红包的发放形式,fixed为固定金额,random为随机金额 "\"prize_type\":\"random\"," . //total_money活动发放的现金总金额,最小金额1.00元 "\"total_money\":\"1.00\"," . //total_num红包发放个数,最小1个,最大10000000个;必须设置为整数 "\"total_num\":\"5\"," . "\"prize_msg\":\"煜雨送您大红包\"," . "\"start_time\":\"NowTime\"," . "\"end_time\":\"2018-11-26 19:03:30\"," . "\"merchant_link\":\"https://www.baidu.com\"," . "\"send_freqency\":\"D3|L10\"" . "}");$result = $aop->execute ($request);var_dump($result);?>
接口调用成功示例:
public 'alipay_marketing_campaign_cash_create_response' => object(stdClass)[10] public 'code' => string '10000' (length=5) public 'msg' => string 'Success' (length=7) public 'crowd_no' => string 'bmhfAI27oG_m1OVdDzn90BEquSXVLD3alk1kU91nMybMnSZ96O-zxUfKlHp5cxmx' (length=64) public 'origin_crowd_no' => string '20181026169410190701192605922004' (length=32) public 'pay_url' => string 'http%3A%2F%2Fauthcenter%2Ealipaydev%2Ecom%3Fgoto%3Dhttp%3A%2F%2Fpromoprod%2Ealipaydev%2Ecom%2Fquery%2FopenCashCrowdPay%2Ehtm%3FcrowdNo%3DbmhfAI27oG%5Fm1OVdDzn90BEquSXVLD3alk1kU91nMybMnSZ96O%2DzxUfKlHp5cxmx' (length=205) public 'sign' => string 'YDx3aojGJN7fwUKzgfwXGoYLlMmGFyqCiPRB5zgy5s1RnqA52T9csJ5Ff2uLlYYxJlo0pVsioCGfWDuzL9j1s8lgis2uOrFkKNU7OTpCIYr4gGpwcV7kCMYMRYXO+6pY+rox7woRefo+pE4WNbibFZ0H3LMPYeksKOkw9LJPKQZDdxWAEEOk0fWId/zYDafXpPa0Rm0NtMOqAtmhYDXVjmgodNb/Ru5b+db0aMpixkI+MYMEvN5TeJ752xNsf2+LjN6iWU7nOheMJmil/HgTxxVP2xZruHHpzU+4gUcqmBZvYb50LVqQ2WAohwrXnCd3r32Z3d3FhwxRX4oMXN2DRQ==' (length=344)
参数说明:
1>.prize_type:现金红包的发放形式,fixed为固定金额,random为随机金额;
2>.total_money:活动发放的现金总金额,最小金额1.00元;
3>.total_num:红包发放个数,最小1个,最大10000000个;必须设置为整数。
4>.pay_url:支付url,有效期为24个小时,需要商家先对其进行UrlDecode处理,然后使用卖家账号登录支付。
支付流程:
将支付链接pay_url进行decode处理,然后在浏览器直接访问该url使用卖家账号:
2、触发现金红包活动接口请求示例
require_once 'AopSdk.php';$aop = new AopClient();$aop->appId = '填写你的沙箱appid';$aop->rsaPrivateKey = '填写您的原始私钥';$aop->alipayrsaPublicKey='填写您的支付宝公钥';$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';$aop->apiVersion = '1.0';$aop->postCharset='utf-8';$aop->format='json';$aop->signType = 'RSA2';$request = new AlipayMarketingCampaignCashTriggerRequest ();$request->setBizContent("{" . "\"user_id\":\"2088102174701092\"," . "\"crowd_no\":\"bmhfAI27oG_m1OVdDzn90MdC2y9YVjhsPLPjJLTHhnDMnSZ96O-zxUfKlHp5cxmx\"," . "\"login_id\":\"dvnvqi3054@sandbox.com\"," . "\"order_price\":\"0.20\"," . "\"out_biz_no\":\"20180919ygyg0004\"" . "}");$result = $aop->execute ( $request);var_dump($result);?>
参数说明:
1>.user_id:用户唯一标识,可通过用户信息授权接口获取;
2>.order_price:设置发送红包的金额,单位为分,100代表1元;
3>.login_id:用户登录账号名:邮箱或手机号。user_id与login_id至少有一个非空,都非空时以user_id为准。
3、更改现金活动状态接口请求示例
require_once 'AopSdk.php';$aop = new AopClient();$aop->appId = '填写你的沙箱appid';$aop->rsaPrivateKey = '填写您的原始私钥';$aop->alipayrsaPublicKey='填写您的支付宝公钥';$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';$aop->apiVersion = '1.0';$aop->postCharset='utf-8';$aop->format='json';$aop->signType = 'RSA2';$request = new AlipayMarketingCampaignCashStatusModifyRequest ();$request->setBizContent("{" . "\"crowd_no\":\"bmhfAI27oG_m1OVdDzn90MdC2y9YVjhsPLPjJLTHhnDMnSZ96O-zxUfKlHp5cxmx\"," . "\"camp_status\":\"PAUSE\"" . "}");$result = $aop->execute ( $request);var_dump($result);?>
接口调用成功示例:
public 'alipay_marketing_campaign_cash_status_modify_response' => object(stdClass)[10] public 'code' => string '10000' (length=5) public 'msg' => string 'Success' (length=7) public 'sign' => string 'GnpwpMfUdFwQIyyqqdNCTP6obNctCaJ+RE7DwfAYABJTRz5ulLZ6ZZ7jYbur+h//hfG4FNAcKkJ5+yWNWGDj+fWRH25NUoyfZM0PTghWqhZaCuOMTnCn7R5Pm+jVwHDu9ngl8JNY816xD9TcQtqFaUdUufGFxGo/9eY8hmnubSdpp9/6iZn09x//TJPPu4DNU0nWELO3NtDOA/qftg9zWmoE5/sFxqTYbgcLOA71EceTZQ/4DwWpavatOhewATUWflVXP9DwWjBNeONFzUuBwl6BJZOCw3H9ldhC+37x4HDiXoK2E68NZaZRMincmWayrY4SHBq20SHvQUR/VqnOxw==' (length=344)
参数说明:
camp_status:修改后的活动状态,只能设置为PAUSE或者READY或者CLOSED。
4、现金活动列表查询接口请求示例
require_once 'AopSdk.php';$aop = new AopClient();$aop->appId = '填写你的沙箱appid';$aop->rsaPrivateKey = '填写您的原始私钥';$aop->alipayrsaPublicKey='填写您的支付宝公钥';$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';$aop->apiVersion = '1.0';$aop->postCharset='utf-8';$aop->format='json';$aop->signType = 'RSA2';$request = new AlipayMarketingCampaignCashListQueryRequest ();$request->setBizContent("{" . "\"camp_status\":\"PAID\"," . "\"page_size\":\"5\"," . "\"page_index\":\"1\"" . "}");$result = $aop->execute ( $request);var_dump($result);?>
接口调用成功示例:
public 'alipay_marketing_campaign_cash_list_query_response' => object(stdClass)[10] public 'code' => string '10000' (length=5) public 'msg' => string 'Success' (length=7) public 'page_index' => string '0' (length=1) public 'page_size' => string '5' (length=1) public 'total_size' => string '0' (length=1) public 'sign' => string 't8e83/k/KfvN2JfjYoM6t28qEW52b4fC4YkSO98e80K34a045yXI1ujClvvU5FNTyNA8drwzUZfHMVcp8ijBwJJoNEryY11LP4rrK6oGLC+xg7FyisBANwj94PdRXfiOd/S5NyxbvNYOvFjhN1NJv52MhOdQTCeomAA3yWVK7bfRYb7m4BH1Usdsgex9CwM2AwT39SR8AMHe8ELaWTksS8KMTAKw0/qotT94KZHKKw454etEfEiPoOnMJNJufuEHrWUX/KZLeg4BYAQMz7iUb0IrmZlLV0638dDPx5pkJr9yeNskqtPjsu810xwii5+kJesdUTRUWeozQpNCfM9yIA==' (length=344)
参数说明:
camp_status要查询的活动状态,不填默认返回所有类型。
5、现金活动详情查询接口请求示例
require_once 'AopSdk.php';$aop = new AopClient();$aop->appId = '填写你的沙箱appid';$aop->rsaPrivateKey = '填写您的原始私钥';$aop->alipayrsaPublicKey='填写您的支付宝公钥';$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';$aop->apiVersion = '1.0';$aop->postCharset='utf-8';$aop->format='json';$aop->signType = 'RSA2';$request = new AlipayMarketingCampaignCashDetailQueryRequest ();$request->setBizContent("{" ."\"crowd_no\":\"bmhfAI27oG_m1OVdDzn90MdC2y9YVjhsPLPjJLTHhnDMnSZ96O-zxUfKlHp5cxmx\"" ."}");$result = $aop->execute ( $request);var_dump($result);?>
接口调用成功示例:
public 'alipay_marketing_campaign_cash_detail_query_response' => object(stdClass)[10] public 'code' => string '10000' (length=5) public 'msg' => string 'Success' (length=7) public 'camp_status' => string 'READY' (length=5) public 'coupon_name' => string '煜雨创建营销活动送红包' (length=33) public 'crowd_no' => string 'bmhfAI27oG_m1OVdDzn90MdC2y9YVjhsPLPjJLTHhnDMnSZ96O-zxUfKlHp5cxmx' (length=64) public 'end_time' => string '2018-12-26 12:48:31' (length=19) public 'origin_crowd_no' => string '20181026169410190701192600817004' (length=32) public 'prize_msg' => string '煜雨送您大红包' (length=21) public 'prize_type' => string 'random' (length=6) public 'send_amount' => string '0.00' (length=4) public 'start_time' => string '2018-10-26 16:00:13' (length=19) public 'total_amount' => string '1.00' (length=4) public 'sign' => string 'ne3iAW8hGGmDuwgKAfAZ83FIQNI3G86IoOOtj2v11tLeg2yb8GjvVL+Zphz5qptaAeOSu/UXHaNkAm/FfspABtpkKpYAIEZTJrRrhlrZUmcKO5HbafN8yTPwKqP5DNb9lYDtA21IePC7fcER8ytgHT9wBgKZjciUhaOEskoIkIzOE9jBiyGILAVN8F0pleQ2PgcCrt3MfgOj/gbRPnPXJzTbh9Hcr9sCIbW9G3ZKzoJ9Ddcw2eZRVWtVAlsTZ4WT+zIgIQFipA3TIRpB+OCZlQqsFCuYsSXPBVmqv2q177cX6nD0yPmVODoz52BZa09lHYSx7YitR+gKalznvLWsCA==' (length=344)
三、显示效果
商户创建完成并生效红包活动后,可在支付宝商家红包后台查看发放情况并下载账单(账单将以T+1时效更新)。
商家红包后台地址:[url]https://hb.alipay.com/mhb/giftList.htm[/url]
钱包中可查询红包的账单信息:
红包说明是固定格式:沙箱环境是:沙箱环境-现金红包;正式环境是:公司名称-现金红包
如果还是报错,请按如下方式进行提问:
正确提问方式:使用环境(沙箱还是正式环境)+接口名称(中文+英文)+ 请求参数 + 报错信息详情