场景:
帮助商户快速创建和发放现金红包,同时可以对已创建的红包进行管理和查看。
流程图:
是否需要签约:是
接口流程图:
需要注意的点:
1.用户领取现金红包后,资金将直接进支付宝余额,并在app首页的红包应用中,查看到出资商户的品牌信息。
2.红包没有被领取完,资金将会在红包失效时(有效时间由商户创建现金红包时指定)退回到商户的支付宝账户中,已发给用户的现金不会收回。
3.ISV在创建一个现金活动后,需要支付,支付成功后,现金活动的状态会变成READY状态,这个时候就可以调用触发接口了;如果没有支付就去调用触发接口,则会报错“现金活动不存在”
4.触发现金红包活动接口alipay.marketing.campaign.cash.trigger接口中的order_price参数单位为分,传入错误格式 接口会报错,一般报错"系统异常"
5.沙箱接入营销活动送红包产品应注意:
A. 在沙箱联调成功后,必须在线上进行测试与验收,返回的业务码以及业务逻辑以线上逻辑为准;
B. 商户账号、用户账号请直接使用沙箱的测试账号;
C. 现金红包后台列表页面暂不支持沙箱,沙箱环境也无法查看对账单,请以线上实际效果为准。
6. 对账相关:商户创建完成并生效红包活动后,可在支付宝商家红包后台查看发放情况并下载账单(账单将以T+1时效更新)。
商家红包后台地址:[url]https://hb.alipay.com/mhb/giftList.htm[/url]
7. 退款相关:若红包直到过期后依然没被领取完,那么资金将会在半小时左右退回至支付宝账户。
代码示例:(这里以沙箱环境为例)
1.创建现金活动
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do", AlipayConfig2.app_id, AlipayConfig2.merchant_private_key, "json", "GBK", AlipayConfig2.alipay_public_key, "RSA2"); AlipayMarketingCampaignCashCreateRequest request = new AlipayMarketingCampaignCashCreateRequest(); //request.putOtherTextParam("app_auth_token", "201803BB8623634c6605477d99cde36916464X33"); AlipayMarketingCampaignCashCreateModel model = new AlipayMarketingCampaignCashCreateModel(); //红包名称,商户在查询列表、详情看到的名字,同时也会显示在商户付款页面。 model.setCouponName("2018年植树节红包"); model.setPrizeType("random"); //活动发放的现金总金额,最小金额1.00元,最大金额10000000.00元。每个红包的最大金额不允许超过200元,最小金额不得低于0.20元。 实际的金额限制可能会根据业务进行动态调整。 model.setTotalMoney("10"); //红包发放个数,最小1个,最大10000000个。 model.setTotalNum("10"); //活动文案,用户在账单、红包中看到的账单描述、红包描述 model.setPrizeMsg("2018年植树节红包"); model.setStartTime("2018-03-13 00:00:00"); model.setEndTime("2018-04-08 00:00:00"); //商户打款后的跳转链接,从支付宝收银台打款成功后的跳转链接。不填时,打款后停留在支付宝支付成功页。商户实际跳转会自动添加crowdNo作为跳转参数。示例: [url]http://www.yourhomepage.com?crowdNo=XXX[/url] model.setMerchantLink("http://www.weibo.com"); model.setSendFreqency("L10"); request.setBizModel(model); //System.out.println("请求参数" + JSONObject.fromObject(request)); AlipayMarketingCampaignCashCreateResponse response; try { response = alipayClient.execute(request); if (response.isSuccess()) System.out.println("调用成功" + response.getBody()); else System.out.println("调用失败" + response.getBody()); } catch (AlipayApiException e) { e.printStackTrace(); }finally { }
响应示例:
{ "alipay_marketing_campaign_cash_create_response":{ "code":"10000", "msg":"Success", "crowd_no":"jJklAvO7xzoEwgPrtNbpevRXpXQxh_3iSH2y7CzQ9dXMnSZ96O-zxUfKlHp5cxmx", "origin_crowd_no":"20180314149410190700140756554004", "pay_url":"http%3A%2F%2Fauthcenter%2Ealipaydev%2Ecom%3Fgoto%3Dhttp%3A%2F%2Fpromoprod%2Ealipaydev%2Ecom%2Fquery%2FopenCashCrowdPay%2Ehtm%3FcrowdNo%3DjJklAvO7xzoEwgPrtNbpevRXpXQxh%5F3iSH2y7CzQ9dXMnSZ96O%2DzxUfKlHp5cxmx" }, "sign":"aGwaDoiP+KURqtghx7hQeYzE32EBaWisXHy+9qXDS8fsSYTh1ER8zE8t1C5nnNObJjsz0iNDYdKosEpsuZjs29T+Zaqt+yoPorwR2JFRA7ZXh6m09/s3uFPDDR6vVszL3ofq/N90qQb0ziaQlybPZ3JLZqzaCqBlIfg+5EhrCAWcJ+h+iZaBBaRvqOcJq/Cdh9sxYkeBlDrr9VkfDZHoWH3ny1Mbwl4+v0bKDAAQJCR/x1/KVPBTlU1OCr3h1a/44ToQZKhw2eYxfKpQ1MVauyAkdBxxORAsG1CYafIdNHFE9govao1LeASpruk9uWkxhGimlHE4HKQ3yINeU6q04w=="}
这里需要注意的是:pay_url参数为活动创建后的付款链接,返回的是urlencode编码后的字符串。需要先进行urldecode解码,然后在浏览器中进行访问,会先进行支付宝登录引导,然后商户进行付款。
2.触发现金红包活动
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do", AlipayConfig2.app_id, AlipayConfig2.merchant_private_key, "json", "GBK", AlipayConfig2.alipay_public_key, "RSA2"); AlipayMarketingCampaignCashTriggerRequest request = new AlipayMarketingCampaignCashTriggerRequest(); AlipayMarketingCampaignCashTriggerModel model = new AlipayMarketingCampaignCashTriggerModel(); model.setCrowdNo("jJklAvO7xzoEwgPrtNbpevRXpXQxh_3iSH2y7CzQ9dXMnSZ96O-zxUfKlHp5cxmx"); //login_id参数和user_id参数至少有一个非空;都非空时,以user_id为准 //如果是沙箱环境,请使用沙箱账号 model.setLoginId("htxhsx7641@sandbox.com"); //单位为分!!!!! model.setOrderPrice("2"); //领取红包的外部业务号,只由可由字母、数字、下划线组成。同一个活动中不可重复,相同的外部业务号会被幂等并返回之前的结果。不填时,系统会生成一个默认固定的外部业务号。 model.setOutBizNo("201803141407301111"); request.setBizModel(model); System.out.println("请求参数" + JSONObject.fromObject(request)); AlipayMarketingCampaignCashTriggerResponse response; try { response = alipayClient.execute(request); if (response.isSuccess()) System.out.println("调用成功" + response.getBody()); else System.out.println("调用失败" + response.getBody()); } catch (AlipayApiException e) { e.printStackTrace(); }
3.现金活动详情查询
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do",AlipayConfig2.app_id,AlipayConfig2.merchant_private_key,"json","GBK",AlipayConfig2.alipay_public_key,"RSA2"); AlipayMarketingCampaignCashDetailQueryRequest request = new AlipayMarketingCampaignCashDetailQueryRequest(); AlipayMarketingCampaignCashDetailQueryModel model=new AlipayMarketingCampaignCashDetailQueryModel(); model.setCrowdNo("jJklAvO7xzoEwgPrtNbpevRXpXQxh_3iSH2y7CzQ9dXMnSZ96O-zxUfKlHp5cxmx"); request.setBizModel(model); //System.out.println("请求参数"+JSONObject.fromObject(request)); AlipayMarketingCampaignCashDetailQueryResponse response ; try { response = alipayClient.execute(request); if(response.isSuccess()) System.out.println("调用成功"+response.getBody()); else System.out.println("调用失败"+response.getBody()); } catch (AlipayApiException e) { e.printStackTrace(); }
4.更改现金活动状态
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do",AlipayConfig2.app_id,AlipayConfig2.merchant_private_key,"json","GBK",AlipayConfig2.alipay_public_key,"RSA2"); AlipayMarketingCampaignCashStatusModifyRequest request = new AlipayMarketingCampaignCashStatusModifyRequest(); AlipayMarketingCampaignCashStatusModifyModel model=new AlipayMarketingCampaignCashStatusModifyModel(); model.setCrowdNo("jJklAvO7xzoEwgPrtNbpevRXpXQxh_3iSH2y7CzQ9dXMnSZ96O-zxUfKlHp5cxmx"); model.setCampStatus("CLOSED"); request.setBizModel(model); //System.out.println("请求参数"+JSONObject.fromObject(request)); AlipayMarketingCampaignCashStatusModifyResponse response ; try { response = alipayClient.execute(request); if(response.isSuccess()) System.out.println("调用成功"+response.getBody()); else System.out.println("调用失败"+response.getBody()); } catch (AlipayApiException e) { e.printStackTrace(); }
5.现金活动列表查询
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do",AlipayConfig2.app_id,AlipayConfig2.merchant_private_key,"json","GBK",AlipayConfig2.alipay_public_key,"RSA2"); AlipayMarketingCampaignCashListQueryRequest request = new AlipayMarketingCampaignCashListQueryRequest(); AlipayMarketingCampaignCashListQueryModel model=new AlipayMarketingCampaignCashListQueryModel(); model.setCampStatus("CLOSED"); model.setPageIndex("1"); model.setPageSize("10"); request.setBizModel(model); System.out.println("请求参数"+JSONObject.fromObject(request)); AlipayMarketingCampaignCashListQueryResponse response; try { response = alipayClient.execute(request); if(response.isSuccess()) System.out.println("调用成功"+response.getBody()); else System.out.println("调用失败"+response.getBody()); } catch (AlipayApiException e) { e.printStackTrace(); }
如果大家还有什么疑问欢迎帖子下面跟帖追问吐槽