coupon param fixed
This commit is contained in:
parent
e1beceb5aa
commit
69a52f09a8
@ -24,91 +24,99 @@ import com.foxinmy.weixin4j.xml.XmlStream;
|
|||||||
*/
|
*/
|
||||||
public class CouponApi extends MchApi {
|
public class CouponApi extends MchApi {
|
||||||
|
|
||||||
public CouponApi(WeixinPayAccount weixinAccount) {
|
public CouponApi(WeixinPayAccount weixinAccount) {
|
||||||
super(weixinAccount);
|
super(weixinAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发放代金券(需要证书)
|
* 发放代金券(需要证书)
|
||||||
*
|
*
|
||||||
* @param couponStockId
|
* @param couponStockId
|
||||||
* 代金券批次id
|
* 代金券批次id
|
||||||
* @param partnerTradeNo
|
* @param partnerTradeNo
|
||||||
* 商户发放凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性
|
* 商户发放凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性
|
||||||
* @param openId
|
* @param openId
|
||||||
* 用户的openid
|
* 用户的openid
|
||||||
* @param opUserId
|
* @param opUserId
|
||||||
* 操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限 可为空
|
* 操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限 可为空
|
||||||
* @return 发放结果
|
* @return 发放结果
|
||||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponResult
|
* @see com.foxinmy.weixin4j.payment.coupon.CouponResult
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
* "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_3">发放代金券接口</a>
|
* "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_3">发放代金券接口</a>
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public CouponResult sendCoupon(String couponStockId, String partnerTradeNo, String openId, String opUserId)
|
public CouponResult sendCoupon(String couponStockId, String partnerTradeNo,
|
||||||
throws WeixinException {
|
String openId, String opUserId) throws WeixinException {
|
||||||
Map<String, String> map = createBaseRequestMap(null);
|
Map<String, String> map = createBaseRequestMap(null);
|
||||||
map.put("coupon_stock_id", couponStockId);
|
map.put("coupon_stock_id", couponStockId);
|
||||||
map.put("partner_trade_no", partnerTradeNo);
|
map.put("partner_trade_no", partnerTradeNo);
|
||||||
map.put("openid", openId);
|
map.put("openid", openId);
|
||||||
// openid记录数(目前支持num=1)
|
// openid记录数(目前支持num=1)
|
||||||
map.put("openid_count", "1");
|
map.put("openid_count", "1");
|
||||||
// 操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限
|
// 操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限
|
||||||
if (StringUtil.isBlank(opUserId)) {
|
if (StringUtil.isBlank(opUserId)) {
|
||||||
opUserId = weixinAccount.getMchId();
|
opUserId = weixinAccount.getMchId();
|
||||||
}
|
}
|
||||||
map.put("op_user_id", opUserId);
|
map.put("op_user_id", opUserId);
|
||||||
map.put("version", "1.0");
|
map.put("version", "1.0");
|
||||||
map.put("type", "XML");
|
map.put("type", "XML");
|
||||||
map.put("sign", weixinSignature.sign(map));
|
map.put("sign", weixinSignature.sign(map));
|
||||||
String param = XmlStream.map2xml(map);
|
String param = XmlStream.map2xml(map);
|
||||||
WeixinResponse response = getWeixinSSLExecutor().post(getRequestUri("coupon_send_uri"), param);
|
WeixinResponse response = getWeixinSSLExecutor().post(
|
||||||
return response.getAsObject(new TypeReference<CouponResult>() {
|
getRequestUri("coupon_send_uri"), param);
|
||||||
});
|
return response.getAsObject(new TypeReference<CouponResult>() {
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询代金券批次
|
* 查询代金券批次
|
||||||
*
|
*
|
||||||
* @param couponStockId
|
* @param couponStockId
|
||||||
* 代金券批次ID
|
* 代金券批次ID
|
||||||
* @return 代金券批次信息
|
* @return 代金券批次信息
|
||||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponStock
|
* @see com.foxinmy.weixin4j.payment.coupon.CouponStock
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
* "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_4">查询代金券批次信息接口</a>
|
* "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_4">查询代金券批次信息接口</a>
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public CouponStock queryCouponStock(String couponStockId) throws WeixinException {
|
public CouponStock queryCouponStock(String couponStockId)
|
||||||
Map<String, String> map = createBaseRequestMap(null);
|
throws WeixinException {
|
||||||
map.put("coupon_stock_id", couponStockId);
|
Map<String, String> map = createBaseRequestMap(null);
|
||||||
map.put("sign", weixinSignature.sign(map));
|
map.put("coupon_stock_id", couponStockId);
|
||||||
String param = XmlStream.map2xml(map);
|
map.put("sign", weixinSignature.sign(map));
|
||||||
WeixinResponse response = weixinExecutor.post(getRequestUri("couponstock_query_uri"), param);
|
String param = XmlStream.map2xml(map);
|
||||||
return response.getAsObject(new TypeReference<CouponStock>() {
|
WeixinResponse response = weixinExecutor.post(
|
||||||
});
|
getRequestUri("couponstock_query_uri"), param);
|
||||||
}
|
return response.getAsObject(new TypeReference<CouponStock>() {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询代金券详细
|
* 查询代金券详细
|
||||||
*
|
*
|
||||||
* @param openId
|
* @param openId
|
||||||
* 用户ID
|
* 用户ID
|
||||||
* @param couponId
|
* @param couponId
|
||||||
* 代金券ID
|
* 代金券ID
|
||||||
* @return 代金券详细信息
|
* @param stockId
|
||||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponDetail
|
* 代金劵对应的批次号
|
||||||
* @see <a href=
|
* @return 代金券详细信息
|
||||||
* "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_5">查询代金券详细信息接口</a>
|
* @see com.foxinmy.weixin4j.payment.coupon.CouponDetail
|
||||||
* @throws WeixinException
|
* @see <a href=
|
||||||
*/
|
* "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_5">查询代金券详细信息接口</a>
|
||||||
public CouponDetail queryCouponDetail(String openId, String couponId) throws WeixinException {
|
* @throws WeixinException
|
||||||
Map<String, String> map = createBaseRequestMap(null);
|
*/
|
||||||
map.put("openid", openId);
|
public CouponDetail queryCouponDetail(String openId, String couponId,
|
||||||
map.put("coupon_id", couponId);
|
String stockId) throws WeixinException {
|
||||||
map.put("sign", weixinSignature.sign(map));
|
Map<String, String> map = createBaseRequestMap(null);
|
||||||
String param = XmlStream.map2xml(map);
|
map.put("openid", openId);
|
||||||
WeixinResponse response = weixinExecutor.post(getRequestUri("coupondetail_query_uri"), param);
|
map.put("coupon_id", couponId);
|
||||||
return response.getAsObject(new TypeReference<CouponDetail>() {
|
map.put("stock_id", stockId);
|
||||||
});
|
map.put("sign", weixinSignature.sign(map));
|
||||||
}
|
String param = XmlStream.map2xml(map);
|
||||||
|
WeixinResponse response = weixinExecutor.post(
|
||||||
|
getRequestUri("coupondetail_query_uri"), param);
|
||||||
|
return response.getAsObject(new TypeReference<CouponDetail>() {
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@ -23,28 +23,31 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
|||||||
*/
|
*/
|
||||||
public class CouponTest extends PayTest {
|
public class CouponTest extends PayTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendCoupon() throws WeixinException {
|
public void sendCoupon() throws WeixinException {
|
||||||
String partnerTradeNo = String.format("%s%s%s", ACCOUNT.getMchId(), DateUtil.fortmat2yyyyMMdd(new Date()), "1");
|
String partnerTradeNo = String.format("%s%s%s", ACCOUNT.getMchId(),
|
||||||
CouponResult result = PAY.sendCoupon("123", partnerTradeNo, "oyFLst1bqtuTcxK-ojF8hOGtLQao", null);
|
DateUtil.fortmat2yyyyMMdd(new Date()), "1");
|
||||||
Assert.assertEquals(Consts.SUCCESS, result.getReturnCode());
|
CouponResult result = PAY.sendCoupon("123", partnerTradeNo,
|
||||||
Assert.assertEquals(Consts.SUCCESS, result.getResultCode());
|
"oyFLst1bqtuTcxK-ojF8hOGtLQao", null);
|
||||||
System.err.println(result);
|
Assert.assertEquals(Consts.SUCCESS, result.getReturnCode());
|
||||||
}
|
Assert.assertEquals(Consts.SUCCESS, result.getResultCode());
|
||||||
|
System.err.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryCouponStock() throws WeixinException {
|
public void queryCouponStock() throws WeixinException {
|
||||||
CouponStock result = PAY.queryCouponStock("couponStockId");
|
CouponStock result = PAY.queryCouponStock("couponStockId");
|
||||||
Assert.assertEquals(Consts.SUCCESS, result.getReturnCode());
|
Assert.assertEquals(Consts.SUCCESS, result.getReturnCode());
|
||||||
Assert.assertEquals(Consts.SUCCESS, result.getResultCode());
|
Assert.assertEquals(Consts.SUCCESS, result.getResultCode());
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryCouponDetail() throws WeixinException {
|
public void queryCouponDetail() throws WeixinException {
|
||||||
CouponDetail result = PAY.queryCouponDetail("openId", "couponId");
|
CouponDetail result = PAY.queryCouponDetail("openId", "couponId",
|
||||||
Assert.assertEquals(Consts.SUCCESS, result.getReturnCode());
|
"stockId");
|
||||||
Assert.assertEquals(Consts.SUCCESS, result.getResultCode());
|
Assert.assertEquals(Consts.SUCCESS, result.getReturnCode());
|
||||||
System.err.println(result);
|
Assert.assertEquals(Consts.SUCCESS, result.getResultCode());
|
||||||
}
|
System.err.println(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user