批量发红包

This commit is contained in:
jinyu 2017-01-05 10:44:53 +08:00
parent a92933ff1b
commit e4a77e96df
7 changed files with 317 additions and 105 deletions

View File

@ -1,8 +1,15 @@
package com.foxinmy.weixin4j.api; package com.foxinmy.weixin4j.api;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -49,11 +56,19 @@ public class CashApi extends MchApi {
* *
* @param redpacket * @param redpacket
* 红包信息 * 红包信息
* @see #sendRedpack(Redpacket,String) * @param openId
* 接受收红包的用户的openid 必填
* @see #sendRedpacks(Redpacket, String...)
*/ */
public RedpacketSendResult sendRedpack(Redpacket redpacket) public RedpacketSendResult sendRedpack(Redpacket redpacket, String openId)
throws WeixinException { throws WeixinException {
return sendRedpack(redpacket, null); try {
return sendRedpacks(redpacket, openId).get(0).get();
} catch (InterruptedException e) {
throw new WeixinException("send redpack error", e);
} catch (ExecutionException e) {
throw new WeixinException("send redpack error", e);
}
} }
/** /**
@ -61,8 +76,8 @@ public class CashApi extends MchApi {
* *
* @param redpacket * @param redpacket
* 红包信息 * 红包信息
* @param appId * @param openIds
* 应用ID 可为空 主要是针对企业号支付时传入的agentid * 接受收红包的用户的openid 必填
* @return 发放结果 * @return 发放结果
* @see com.foxinmy.weixin4j.payment.mch.Redpacket * @see com.foxinmy.weixin4j.payment.mch.Redpacket
* @see com.foxinmy.weixin4j.payment.mch.RedpacketSendResult * @see com.foxinmy.weixin4j.payment.mch.RedpacketSendResult
@ -74,23 +89,44 @@ public class CashApi extends MchApi {
* 发放裂变红包接口</a> * 发放裂变红包接口</a>
* @throws WeixinException * @throws WeixinException
*/ */
public RedpacketSendResult sendRedpack(Redpacket redpacket, String appId) public List<Future<RedpacketSendResult>> sendRedpacks(Redpacket redpacket,
throws WeixinException { String... openIds) {
String appId = redpacket.getAppId();
super.declareMerchant(redpacket); super.declareMerchant(redpacket);
JSONObject obj = (JSONObject) JSON.toJSON(redpacket); final JSONObject obj = (JSONObject) JSON.toJSON(redpacket);
if (StringUtil.isNotBlank(appId)) { if (StringUtil.isNotBlank(appId)) {
obj.put("appid", appId); obj.put("appid", appId);
} }
obj.put("wxappid", obj.remove("appid")); obj.put("wxappid", obj.remove("appid"));
obj.put("sign", weixinSignature.sign(obj)); final String redpack_uri = redpacket.getTotalNum() > 1 ? getRequestUri("groupredpack_send_uri")
String param = XmlStream.map2xml(obj); : getRequestUri("redpack_send_uri");
WeixinResponse response = getWeixinSSLExecutor() int sendLength = openIds.length;
.post(redpacket.getTotalNum() > 1 ? getRequestUri("groupredpack_send_uri") ExecutorService sendExecutor = Executors.newFixedThreadPool(Math.max(1,
: getRequestUri("redpack_send_uri"), param); sendLength / 10)); // 十分之一?
String text = response.getAsString() List<Future<RedpacketSendResult>> callSendList = new ArrayList<Future<RedpacketSendResult>>(
.replaceFirst("<wxappid>", "<appid>") sendLength);
.replaceFirst("</wxappid>", "</appid>"); for (final String openId : openIds) {
return XmlStream.fromXML(text, RedpacketSendResult.class); Future<RedpacketSendResult> futureSend = sendExecutor
.submit(new Callable<RedpacketSendResult>() {
@Override
public RedpacketSendResult call() throws Exception {
obj.put("re_openid", openId);
obj.put("sign", weixinSignature.sign(obj));
String param = XmlStream.map2xml(obj);
WeixinResponse response = getWeixinSSLExecutor()
.post(redpack_uri, param);
String text = response.getAsString()
.replaceFirst("<wxappid>", "<appid>")
.replaceFirst("</wxappid>", "</appid>");
return XmlStream.fromXML(text,
RedpacketSendResult.class);
}
});
callSendList.add(futureSend);
}
// 关闭启动线程,不再接受新的任务
sendExecutor.shutdown();
return callSendList;
} }
/** /**

View File

@ -3,6 +3,8 @@ package com.foxinmy.weixin4j.payment;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.concurrent.Future;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.foxinmy.weixin4j.api.CashApi; import com.foxinmy.weixin4j.api.CashApi;
@ -679,11 +681,15 @@ public class WeixinPayProxy {
* *
* @param redpacket * @param redpacket
* 红包信息 * 红包信息
* @see #sendRedpack(Redpacket,String) * @param openId
* 接受收红包的用户的openid 必填
* @see com.foxinmy.weixin4j.api.CashApi
* @throws WeixinException
* @see #sendRedpacks(Redpacket, String...)
*/ */
public RedpacketSendResult sendRedpack(Redpacket redpacket) public RedpacketSendResult sendRedpack(Redpacket redpacket, String openId)
throws WeixinException { throws WeixinException {
return cashApi.sendRedpack(redpacket); return cashApi.sendRedpack(redpacket, openId);
} }
/** /**
@ -691,8 +697,8 @@ public class WeixinPayProxy {
* *
* @param redpacket * @param redpacket
* 红包信息 * 红包信息
* @param appId * @param openIds
* 应用ID 可为空 主要是针对企业号支付时传入的agentid * 接受收红包的用户的openid 必填
* @return 发放结果 * @return 发放结果
* @see com.foxinmy.weixin4j.api.CashApi * @see com.foxinmy.weixin4j.api.CashApi
* @see com.foxinmy.weixin4j.payment.mch.Redpacket * @see com.foxinmy.weixin4j.payment.mch.Redpacket
@ -705,9 +711,9 @@ public class WeixinPayProxy {
* 发放裂变红包接口</a> * 发放裂变红包接口</a>
* @throws WeixinException * @throws WeixinException
*/ */
public RedpacketSendResult sendRedpack(Redpacket redpacket, String appId) public List<Future<RedpacketSendResult>> sendRedpacks(Redpacket redpacket,
throws WeixinException { String... openIds) {
return cashApi.sendRedpack(redpacket, appId); return cashApi.sendRedpacks(redpacket, openIds);
} }
/** /**

View File

@ -6,6 +6,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.type.mch.RedpacketSceneType;
import com.foxinmy.weixin4j.util.DateUtil; import com.foxinmy.weixin4j.util.DateUtil;
/** /**
@ -38,12 +39,6 @@ public class Redpacket extends MerchantResult {
@XmlElement(name = "send_name") @XmlElement(name = "send_name")
@JSONField(name = "send_name") @JSONField(name = "send_name")
private String sendName; private String sendName;
/**
* 接收红包的用户的openid
*/
@XmlElement(name = "re_openid")
@JSONField(name = "re_openid")
private String openId;
/** /**
* 付款金额单位分 * 付款金额单位分
*/ */
@ -96,6 +91,18 @@ public class Redpacket extends MerchantResult {
@XmlElement(name = "consume_mch_id") @XmlElement(name = "consume_mch_id")
@JSONField(name = "consume_mch_id") @JSONField(name = "consume_mch_id")
private String consumeMchId; private String consumeMchId;
/**
* 发放红包使用场景红包金额大于200时必传
*/
@XmlElement(name = "scene_id")
@JSONField(name = "scene_id")
private RedpacketSceneType sceneType;
/**
* 活动信息
*/
@XmlElement(name = "risk_info")
@JSONField(name = "risk_info")
private String risk;
protected Redpacket() { protected Redpacket() {
// jaxb required // jaxb required
@ -108,8 +115,6 @@ public class Redpacket extends MerchantResult {
* 商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用 必填 * 商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用 必填
* @param sendName * @param sendName
* 红包发送者名称 必填 * 红包发送者名称 必填
* @param openId
* 接受收红包的用户的openid 必填
* @param totalAmount * @param totalAmount
* 付款金额 <font color="red">单位为元,自动格式化为分</font> 必填 * 付款金额 <font color="red">单位为元,自动格式化为分</font> 必填
* @param totalNum * @param totalNum
@ -123,12 +128,11 @@ public class Redpacket extends MerchantResult {
* @param remark * @param remark
* 备注 必填 * 备注 必填
*/ */
public Redpacket(String outTradeNo, String sendName, String openId, public Redpacket(String outTradeNo, String sendName, double totalAmount,
double totalAmount, int totalNum, String wishing, String clientIp, int totalNum, String wishing, String clientIp, String actName,
String actName, String remark) { String remark) {
this.outTradeNo = outTradeNo; this.outTradeNo = outTradeNo;
this.sendName = sendName; this.sendName = sendName;
this.openId = openId;
this.totalNum = totalNum; this.totalNum = totalNum;
this.wishing = wishing; this.wishing = wishing;
this.clientIp = clientIp; this.clientIp = clientIp;
@ -146,14 +150,10 @@ public class Redpacket extends MerchantResult {
return sendName; return sendName;
} }
public String getOpenId() {
return openId;
}
public int getTotalAmount() { public int getTotalAmount() {
return totalAmount; return totalAmount;
} }
/** /**
* <font color="red">调用接口获取单位为分,get方法转换为元方便使用</font> * <font color="red">调用接口获取单位为分,get方法转换为元方便使用</font>
* *
@ -204,14 +204,34 @@ public class Redpacket extends MerchantResult {
this.consumeMchId = consumeMchId; this.consumeMchId = consumeMchId;
} }
public RedpacketSceneType getSceneType() {
return sceneType;
}
public void setSceneType(RedpacketSceneType sceneType) {
this.sceneType = sceneType;
}
public String getRisk() {
return risk;
}
public void setRisk(String risk) {
this.risk = risk;
}
public void setRisk(RedpacketRisk risk) {
this.risk = risk.toContent();
}
@Override @Override
public String toString() { public String toString() {
return "Redpacket [msgAppId=" + msgAppId + ", consumeMchId=" return "Redpacket [outTradeNo=" + outTradeNo + ", sendName=" + sendName
+ consumeMchId + ", outTradeNo=" + outTradeNo + ", sendName=" + ", totalAmount=" + totalAmount + ", totalNum=" + totalNum
+ sendName + ", openId=" + openId + ", totalAmount=" + ", amtType=" + amtType + ", wishing=" + wishing
+ totalAmount + ", totalNum=" + totalNum + ", amtType=" + ", clientIp=" + clientIp + ", actName=" + actName
+ amtType + ", wishing=" + wishing + ", clientIp=" + clientIp + ", remark=" + remark + ", msgAppId=" + msgAppId
+ ", actName=" + actName + ", remark=" + remark + ", " + ", consumeMchId=" + consumeMchId + ", sceneType=" + sceneType
+ super.toString() + "]"; + ", risk=" + risk + ", " + super.toString() + "]";
} }
} }

View File

@ -0,0 +1,85 @@
package com.foxinmy.weixin4j.payment.mch;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import com.foxinmy.weixin4j.util.Consts;
import com.foxinmy.weixin4j.util.DateUtil;
import com.foxinmy.weixin4j.util.MapUtil;
/**
* 发送红包的活动信息
*
* @className RedpacketRisk
* @author jinyu(foxinmy@gmail.com)
* @date 2017年1月4日
* @since JDK 1.6
* @see
*/
public class RedpacketRisk {
private Map<String, String> risk;
public RedpacketRisk() {
this.risk = new HashMap<String, String>();
}
/**
* 用户操作的时间戳
*
* @return
*/
public RedpacketRisk postTimestamp() {
risk.put("posttime", DateUtil.timestamp2string());
return this;
}
/**
* 业务系统账号的手机号国家代码-手机号不需要+
*
* @param mobile
* @return
*/
public RedpacketRisk mobile(String mobile) {
risk.put("mobile", mobile);
return this;
}
/**
* 用户操作的客户端版本
*
* @param clientVersion
* @return
*/
public RedpacketRisk clientVersion(String clientVersion) {
risk.put("clientversion", clientVersion);
return this;
}
/**
* mac 地址或者设备唯一标识
*
* @param deviceid
* @return
*/
public RedpacketRisk deviceid(String deviceid) {
risk.put("deviceid", deviceid);
return this;
}
public Map<String, String> getRisk() {
return risk;
}
public String toContent() {
if (risk.isEmpty())
return null;
try {
return URLEncoder.encode(MapUtil.toJoinString(risk, false, false),
Consts.UTF_8.name());
} catch (UnsupportedEncodingException e) {
return null;
}
}
}

View File

@ -0,0 +1,44 @@
package com.foxinmy.weixin4j.type.mch;
/**
* 发放红包使用场景
*
* @className RedpacketSceneType
* @author jinyu(foxinmy@gmail.com)
* @date 2017年1月4日
* @since JDK 1.6
*/
public enum RedpacketSceneType {
/**
* 商品促销
*/
PRODUCT_1,
/**
* 抽奖
*/
PRODUCT_2,
/**
* 虚拟物品兑奖
*/
PRODUCT_3,
/**
* 企业内部福利
*/
PRODUCT_4,
/**
* 渠道分润
*/
PRODUCT_5,
/**
* 保险回馈
*/
PRODUCT_6,
/**
* 彩票派奖
*/
PRODUCT_7,
/**
* 税务刮奖
*/
PRODUCT_8
}

View File

@ -26,10 +26,10 @@ public class CashTest extends PayTest {
@Test @Test
public void sendRedpacket() throws WeixinException { public void sendRedpacket() throws WeixinException {
Redpacket redpacket = new Redpacket("HB001", "无忧钱庄", Redpacket redpacket = new Redpacket("HB001", "无忧钱庄", 1d, 1, "红包测试",
"oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d, 1, "红包测试", "127.0.0.1", "127.0.0.1", "快来领取红包吧!", "来就送钱");
"快来领取红包吧!", "来就送钱"); RedpacketSendResult result = PAY.sendRedpack(redpacket,
RedpacketSendResult result = PAY.sendRedpack(redpacket); "oyFLst1bqtuTcxK-ojF8hOGtLQao");
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);

View File

@ -168,13 +168,19 @@ public class CardApi extends MpApi {
* 1.同时支持openidusername两种字段设置白名单总数上限为10个 * 1.同时支持openidusername两种字段设置白名单总数上限为10个
* 2.设置测试白名单接口为全量设置即测试名单发生变化时需调用该接口重新传入所有测试人员的ID. * 2.设置测试白名单接口为全量设置即测试名单发生变化时需调用该接口重新传入所有测试人员的ID.
* 3.白名单用户领取该卡券时将无视卡券失效状态请开发者注意 * 3.白名单用户领取该卡券时将无视卡券失效状态请开发者注意
* @param openIds the open ids *
* @param userNames the user names * @param openIds
* the open ids
* @param userNames
* the user names
* @author fengyapeng * @author fengyapeng
* @since 2016 -12-20 11:22:57 * @since 2016 -12-20 11:22:57
* @see <a href='https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025062&token=&lang=zh_CN&anchor=6'>设置测试白名单</a> * @see <a href=
* 'https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025062&token=&lang=zh_CN&anchor=6'>设置测试白名单</
* a >
*/ */
public void setTestWhiteList(List<String> openIds, List<String> userNames) throws WeixinException { public ApiResult setTestWhiteList(List<String> openIds,
List<String> userNames) throws WeixinException {
JSONObject requestObj = new JSONObject(); JSONObject requestObj = new JSONObject();
if (openIds != null && openIds.size() > 0) { if (openIds != null && openIds.size() > 0) {
requestObj.put("openid", openIds); requestObj.put("openid", openIds);
@ -185,27 +191,34 @@ public class CardApi extends MpApi {
String card_set_test_whitelist_uri = getRequestUri("card_set_test_whitelist_uri"); String card_set_test_whitelist_uri = getRequestUri("card_set_test_whitelist_uri");
Token token = tokenManager.getCache(); Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post( WeixinResponse response = weixinExecutor.post(
String.format(card_set_test_whitelist_uri, token.getAccessToken()), String.format(card_set_test_whitelist_uri,
requestObj.toJSONString()); token.getAccessToken()), requestObj.toJSONString());
return response.getAsResult();
} }
/** /**
* 查看获取卡券的审核状态 * 查看获取卡券的审核状态
* @see <a href='https://mp.weixin.qq.com/wiki?action=doc&id=mp1451025272&t=0.18670321276182844#3'> 查看卡券详情</a> *
* @see <a href=
* 'https://mp.weixin.qq.com/wiki?action=doc&id=mp1451025272&t=0.18670321276182844#3'
* > 查看卡券详情</a>
* *
* @author fengyapeng * @author fengyapeng
* @since 2016 -12-20 11:48:23 * @since 2016 -12-20 11:48:23
*/ */
public CardStatus queryCardStatus(String cardId) throws WeixinException { public CardStatus queryCardStatus(String cardId) throws WeixinException {
JSONObject requestObj = new JSONObject(); JSONObject requestObj = new JSONObject();
requestObj.put("card_id",cardId); requestObj.put("card_id", cardId);
String card_get_uri = getRequestUri("card_get_uri"); String card_get_uri = getRequestUri("card_get_uri");
Token token = tokenManager.getCache(); Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(card_get_uri, token.getAccessToken()),requestObj.toJSONString()); WeixinResponse response = weixinExecutor.post(
String.format(card_get_uri, token.getAccessToken()),
requestObj.toJSONString());
JSONObject responseAsJson = response.getAsJson(); JSONObject responseAsJson = response.getAsJson();
JSONObject card = responseAsJson.getJSONObject("card"); JSONObject card = responseAsJson.getJSONObject("card");
String cardType = card.getString("card_type"); String cardType = card.getString("card_type");
JSONObject baseInfo = card.getJSONObject(cardType.toLowerCase()).getJSONObject("base_info"); JSONObject baseInfo = card.getJSONObject(cardType.toLowerCase())
.getJSONObject("base_info");
String status = baseInfo.getString("status"); String status = baseInfo.getString("status");
return CardStatus.valueOf(status); return CardStatus.valueOf(status);
} }
@ -213,15 +226,19 @@ public class CardApi extends MpApi {
/** /**
* 支持更新所有卡券类型的部分通用字段及特殊卡券会员卡飞机票电影票会议门票中特定字段的信息 * 支持更新所有卡券类型的部分通用字段及特殊卡券会员卡飞机票电影票会议门票中特定字段的信息
* *
* @param cardId the card id * @param cardId
* @param card the card * the card id
* @param card
* the card
* @return 是否提交审核false为修改后不会重新提审true为修改字段后重新提审该卡券的状态变为审核中 * @return 是否提交审核false为修改后不会重新提审true为修改字段后重新提审该卡券的状态变为审核中
* @throws WeixinException the weixin exception * @throws WeixinException
* the weixin exception
* @author fengyapeng * @author fengyapeng
* @see * @see
* @since 2016 -12-21 15:29:10 * @since 2016 -12-21 15:29:10
*/ */
public Boolean updateCardCoupon(String cardId, CardCoupon card) throws WeixinException { public Boolean updateCardCoupon(String cardId, CardCoupon card)
throws WeixinException {
JSONObject request = new JSONObject(); JSONObject request = new JSONObject();
request.put("card_id", cardId); request.put("card_id", cardId);
CardType cardType = card.getCardType(); CardType cardType = card.getCardType();
@ -229,84 +246,88 @@ public class CardApi extends MpApi {
request.put(cardType.name().toLowerCase(), card); request.put(cardType.name().toLowerCase(), card);
String card_update_uri = getRequestUri("card_update_uri"); String card_update_uri = getRequestUri("card_update_uri");
Token token = tokenManager.getCache(); Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(card_update_uri,token.getAccessToken()),JSON.toJSONString(request)); WeixinResponse response = weixinExecutor.post(
JSONObject jsonObject= response.getAsJson(); String.format(card_update_uri, token.getAccessToken()),
return jsonObject.getBoolean("send_check"); JSON.toJSONString(request));
JSONObject jsonObject = response.getAsJson();
return jsonObject.getBoolean("send_check");
} }
/** /**
* 激活方式说明 * 激活方式说明 接口激活通常需要开发者开发用户填写资料的网页通常有两种激活流程 1.
* 接口激活通常需要开发者开发用户填写资料的网页通常有两种激活流程 * 用户必须在填写资料后才能领卡领卡后开发者调用激活接口为用户激活会员卡 2.
* 1. 用户必须在填写资料后才能领卡领卡后开发者调用激活接口为用户激活会员卡 * 是用户可以先领取会员卡点击激活会员卡跳转至开发者设置的资料填写页面填写完成后开发者调用激活接口为用户激活会员卡
* 2. 是用户可以先领取会员卡点击激活会员卡跳转至开发者设置的资料填写页面填写完成后开发者调用激活接口为用户激活会员卡
* *
* @see <a href='https://mp.weixin.qq.com/wiki?action=doc&id=mp1451025283&t=0.8029895777585161#6.1'>接口激活</a> * @see <a href=
* 'https://mp.weixin.qq.com/wiki?action=doc&id=mp1451025283&t=0.8029895777585161#6.1'>接口激活</
* a >
*/ */
public ApiResult activateMemberCard(MemberInitInfo memberInitInfo) throws WeixinException { public ApiResult activateMemberCard(MemberInitInfo memberInitInfo)
throws WeixinException {
String card_member_card_activate_uri = getRequestUri("card_member_card_activate_uri"); String card_member_card_activate_uri = getRequestUri("card_member_card_activate_uri");
Token token = tokenManager.getCache(); Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor WeixinResponse response = weixinExecutor.post(
.post(String.format(card_member_card_activate_uri, token.getAccessToken()), JSON.toJSONString(memberInitInfo)); String.format(card_member_card_activate_uri,
token.getAccessToken()),
JSON.toJSONString(memberInitInfo));
return response.getAsResult(); return response.getAsResult();
} }
/** /**
* 设置开卡字段接口 * 设置开卡字段接口 开发者在创建时填入wx_activate字段后 需要调用该接口设置用户激活时需要填写的选项否则一键开卡设置不生效
* 开发者在创建时填入wx_activate字段后
* 需要调用该接口设置用户激活时需要填写的选项否则一键开卡设置不生效
* *
* @see <a href='https://mp.weixin.qq.com/wiki?action=doc&id=mp1451025283&t=0.8029895777585161#6.2'>一键激活</a> * @see <a href=
* 'https://mp.weixin.qq.com/wiki?action=doc&id=mp1451025283&t=0.8029895777585161#6.2'>一键激活</
* a >
*/ */
public ApiResult setActivateUserForm(MemberUserForm memberUserForm) throws WeixinException { public ApiResult setActivateUserForm(MemberUserForm memberUserForm)
throws WeixinException {
String user_form_uri = getRequestUri("card_member_card_activate_user_form_uri"); String user_form_uri = getRequestUri("card_member_card_activate_user_form_uri");
Token token = tokenManager.getCache(); Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor WeixinResponse response = weixinExecutor.post(
.post(String.format(user_form_uri, token.getAccessToken()), JSON.toJSONString(memberUserForm)); String.format(user_form_uri, token.getAccessToken()),
JSON.toJSONString(memberUserForm));
return response.getAsResult(); return response.getAsResult();
} }
/** /**
* 拉取会员信息接口 * 拉取会员信息接口
* *
* @param cardId the card id * @param cardId
* @param code the code * the card id
* @param code
* the code
* @author fengyapeng * @author fengyapeng
* @since 2016 -12-21 11:28:45 * @since 2016 -12-21 11:28:45
*/ */
public MemberUserInfo getMemberUserInfo(String cardId, String code) throws WeixinException { public MemberUserInfo getMemberUserInfo(String cardId, String code)
throws WeixinException {
String user_info_uri = getRequestUri("card_member_card_user_info_uri"); String user_info_uri = getRequestUri("card_member_card_user_info_uri");
Token token = tokenManager.getCache(); Token token = tokenManager.getCache();
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("card_id", cardId); jsonObject.put("card_id", cardId);
jsonObject.put("code", code); jsonObject.put("code", code);
WeixinResponse response = weixinExecutor.post(String.format(user_info_uri, token.getAccessToken()), JSON.toJSONString(jsonObject)); WeixinResponse response = weixinExecutor.post(
String.format(user_info_uri, token.getAccessToken()),
JSON.toJSONString(jsonObject));
return response.getAsObject(new TypeReference<MemberUserInfo>() { return response.getAsObject(new TypeReference<MemberUserInfo>() {
}); });
} }
/** /**
* 更新会员 * 更新会员 result_bonus 当前用户积分总额 result_balance 当前用户预存总金额 openid 用户openid
* result_bonus 当前用户积分总额 *
* result_balance 当前用户预存总金额
* openid 用户openid
* @param updateInfo * @param updateInfo
* @return * @return
* @throws WeixinException * @throws WeixinException
*/ */
public JSONObject updateMemberUserInfo(MemberUpdateInfo updateInfo) throws WeixinException { public JSONObject updateMemberUserInfo(MemberUpdateInfo updateInfo)
throws WeixinException {
String card_member_card_update_user_uri = getRequestUri("card_member_card_update_user_uri"); String card_member_card_update_user_uri = getRequestUri("card_member_card_update_user_uri");
Token token = tokenManager.getCache(); Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor WeixinResponse response = weixinExecutor.post(
.post(String.format(card_member_card_update_user_uri, token.getAccessToken()), JSON.toJSONString(updateInfo)); String.format(card_member_card_update_user_uri,
token.getAccessToken()), JSON.toJSONString(updateInfo));
return response.getAsJson(); return response.getAsJson();
} }
} }