1 package com.foxinmy.weixin4j.api;
2
3 import java.util.Map;
4
5 import com.alibaba.fastjson.TypeReference;
6 import com.foxinmy.weixin4j.exception.WeixinException;
7 import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
8 import com.foxinmy.weixin4j.model.WeixinPayAccount;
9 import com.foxinmy.weixin4j.payment.coupon.CouponDetail;
10 import com.foxinmy.weixin4j.payment.coupon.CouponResult;
11 import com.foxinmy.weixin4j.payment.coupon.CouponStock;
12 import com.foxinmy.weixin4j.util.StringUtil;
13 import com.foxinmy.weixin4j.xml.XmlStream;
14
15
16
17
18
19
20
21
22
23
24
25
26 @Deprecated
27 public class CouponApi extends MchApi {
28
29 public CouponApi(WeixinPayAccount weixinAccount) {
30 super(weixinAccount);
31 }
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public CouponResult sendCoupon(String couponStockId, String partnerTradeNo,
51 String openId, String opUserId) throws WeixinException {
52 Map<String, String> map = createBaseRequestMap(null);
53 map.put("coupon_stock_id", couponStockId);
54 map.put("partner_trade_no", partnerTradeNo);
55 map.put("openid", openId);
56
57 map.put("openid_count", "1");
58
59 if (StringUtil.isBlank(opUserId)) {
60 opUserId = weixinAccount.getMchId();
61 }
62 map.put("op_user_id", opUserId);
63 map.put("version", "1.0");
64 map.put("type", "XML");
65 map.put("sign", weixinSignature.sign(map));
66 String param = XmlStream.map2xml(map);
67 WeixinResponse response = getWeixinSSLExecutor().post(
68 getRequestUri("coupon_send_uri"), param);
69 return response.getAsObject(new TypeReference<CouponResult>() {
70 });
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84 public CouponStock queryCouponStock(String couponStockId)
85 throws WeixinException {
86 Map<String, String> map = createBaseRequestMap(null);
87 map.put("coupon_stock_id", couponStockId);
88 map.put("sign", weixinSignature.sign(map));
89 String param = XmlStream.map2xml(map);
90 WeixinResponse response = weixinExecutor.post(
91 getRequestUri("couponstock_query_uri"), param);
92 return response.getAsObject(new TypeReference<CouponStock>() {
93 });
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 public CouponDetail queryCouponDetail(String openId, String couponId,
112 String stockId) throws WeixinException {
113 Map<String, String> map = createBaseRequestMap(null);
114 map.put("openid", openId);
115 map.put("coupon_id", couponId);
116 map.put("stock_id", stockId);
117 map.put("sign", weixinSignature.sign(map));
118 String param = XmlStream.map2xml(map);
119 WeixinResponse response = weixinExecutor.post(
120 getRequestUri("coupondetail_query_uri"), param);
121 return response.getAsObject(new TypeReference<CouponDetail>() {
122 });
123 }
124 }