From a304bc573b2413de37454dd00b759b60c4a8f5dc Mon Sep 17 00:00:00 2001 From: devina Date: Tue, 20 Sep 2016 21:03:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AE=A2=E5=8D=95=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E7=8A=B6=E6=80=81=E8=BF=94=E5=9B=9E=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=9CWxMpPayResult=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpUserTagService.java | 15 +- .../mp/api/impl/WxMpUserTagServiceImpl.java | 26 +++- .../weixin/mp/bean/result/WxMpPayResult.java | 131 +++++++++++------- .../weixin/mp/bean/tag/WxTagListUser.java | 92 ++++++++++++ .../api/impl/WxMpUserTagServiceImplTest.java | 21 +-- 5 files changed, 222 insertions(+), 63 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java index bcf657fa..128f2cb7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpUserTagService.java @@ -1,10 +1,11 @@ package me.chanjar.weixin.mp.api; -import java.util.List; - import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import java.util.List; + /** * 用户标签管理相关接口 * Created by Binary Wang on 2016/9/2. @@ -55,4 +56,14 @@ public interface WxMpUserTagService { */ Boolean tagDelete(Integer id) throws WxErrorException; + /** + *
+   * 获取标签下粉丝列表
+   * 详情请见:用户标签管理
+   * 接口url格式: https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=ACCESS_TOKEN
+   * 
+ * + */ + WxTagListUser tagListUser(Integer tagId, String nextOpenid) throws WxErrorException; + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java index c2167556..bb6daf63 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImpl.java @@ -1,17 +1,17 @@ package me.chanjar.weixin.mp.api.impl; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.JsonObject; - import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserTagService; +import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; /** * @@ -92,4 +92,18 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService { throw new WxErrorException(wxError); } + + @Override + public WxTagListUser tagListUser(Integer tagId, String nextOpenid) throws WxErrorException { + String url = "https://api.weixin.qq.com/cgi-bin/user/tag/get"; + + JsonObject json = new JsonObject(); + json.addProperty("tagid", tagId); + json.addProperty("next_openid", StringUtils.trimToEmpty(nextOpenid)); + + String responseContent = this.wxMpService.post(url, json.toString()); + this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, json.toString(), + responseContent); + return WxTagListUser.fromJson(responseContent); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java index 1ea8fd65..774cd442 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java @@ -41,93 +41,102 @@ public class WxMpPayResult implements Serializable { private String out_trade_no; private String attach; private String time_end; - + /** + * 现金支付金额 cash_fee 是 Int 100 现金支付金额订单现金支付金额,详见支付金额 + */ + private String cash_fee; + + /** + * 现金支付货币类型 cash_fee_type 否 + * + */ + private String cash_fee_type; public String getReturn_code() { - return this.return_code; + return return_code; } public String getReturn_msg() { - return this.return_msg; + return return_msg; } public String getAppid() { - return this.appid; + return appid; } public String getMch_id() { - return this.mch_id; + return mch_id; } public String getNonce_str() { - return this.nonce_str; + return nonce_str; } public String getSign() { - return this.sign; + return sign; } public String getResult_code() { - return this.result_code; + return result_code; } public String getErr_code() { - return this.err_code; + return err_code; } public String getErr_code_des() { - return this.err_code_des; + return err_code_des; } public String getTrade_state() { - return this.trade_state; + return trade_state; } public String getDevice_info() { - return this.device_info; + return device_info; } public String getOpenid() { - return this.openid; + return openid; } public String getIs_subscribe() { - return this.is_subscribe; + return is_subscribe; } public String getTrade_type() { - return this.trade_type; + return trade_type; } public String getBank_type() { - return this.bank_type; + return bank_type; } public String getTotal_fee() { - return this.total_fee; + return total_fee; } public String getCoupon_fee() { - return this.coupon_fee; + return coupon_fee; } public String getFee_type() { - return this.fee_type; + return fee_type; } public String getTransaction_id() { - return this.transaction_id; + return transaction_id; } public String getOut_trade_no() { - return this.out_trade_no; + return out_trade_no; } public String getAttach() { - return this.attach; + return attach; } public String getTime_end() { - return this.time_end; + return time_end; } public void setReturn_code(String return_code) { @@ -219,7 +228,7 @@ public class WxMpPayResult implements Serializable { } public String getTrade_state_desc() { - return this.trade_state_desc; + return trade_state_desc; } public void setTrade_state_desc(String trade_state_desc) { @@ -229,29 +238,57 @@ public class WxMpPayResult implements Serializable { @Override public String toString() { return "WxMpPayResult{" + - "return_code=" + this.return_code + - ", return_msg='" + this.return_msg + '\'' + - ", appid='" + this.appid + '\'' + - ", mch_id='" + this.mch_id + '\'' + - ", nonce_str='" + this.nonce_str + '\'' + - ", sign='" + this.sign + '\'' + - ", result_code='" + this.result_code + '\'' + - ", err_code='" + this.err_code + '\'' + - ", err_code_des='" + this.err_code_des + '\'' + - ", trade_state=" + this.trade_state + - ", trade_state_desc=" + this.trade_state_desc + - ", device_info='" + this.device_info + '\'' + - ", openid='" + this.openid + '\'' + - ", is_subscribe='" + this.is_subscribe + '\'' + - ", trade_type='" + this.trade_type + '\'' + - ", bank_type='" + this.bank_type + '\'' + - ", total_fee='" + this.total_fee + '\'' + - ", coupon_fee='" + this.coupon_fee + '\'' + - ", fee_type='" + this.fee_type + '\'' + - ", transaction_id='" + this.transaction_id + '\'' + - ", out_trade_no='" + this.out_trade_no + '\'' + - ", attach='" + this.attach + '\'' + - ", time_end='" + this.time_end + '\'' + + "return_code=" + return_code + + ", return_msg='" + return_msg + '\'' + + ", appid='" + appid + '\'' + + ", mch_id='" + mch_id + '\'' + + ", nonce_str='" + nonce_str + '\'' + + ", sign='" + sign + '\'' + + ", result_code='" + result_code + '\'' + + ", err_code='" + err_code + '\'' + + ", err_code_des='" + err_code_des + '\'' + + ", trade_state=" + trade_state + + ", trade_state_desc=" + trade_state_desc + + ", device_info='" + device_info + '\'' + + ", openid='" + openid + '\'' + + ", is_subscribe='" + is_subscribe + '\'' + + ", trade_type='" + trade_type + '\'' + + ", bank_type='" + bank_type + '\'' + + ", total_fee='" + total_fee + '\'' + + ", coupon_fee='" + coupon_fee + '\'' + + ", fee_type='" + fee_type + '\'' + + ", transaction_id='" + transaction_id + '\'' + + ", out_trade_no='" + out_trade_no + '\'' + + ", attach='" + attach + '\'' + + ", time_end='" + time_end + '\'' + '}'; } + +/** + * @return the cash_fee + */ +public String getCash_fee() { + return cash_fee; +} + +/** + * @param cash_fee the cash_fee to set + */ +public void setCash_fee(String cash_fee) { + this.cash_fee = cash_fee; +} + +/** + * @return the cash_fee_type + */ +public String getCash_fee_type() { + return cash_fee_type; +} + +/** + * @param cash_fee_type the cash_fee_type to set + */ +public void setCash_fee_type(String cash_fee_type) { + this.cash_fee_type = cash_fee_type; +} } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java new file mode 100644 index 00000000..0ba48edc --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/tag/WxTagListUser.java @@ -0,0 +1,92 @@ +package me.chanjar.weixin.mp.bean.tag; + +import com.google.gson.annotations.SerializedName; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.List; + +/** + * 获取标签下粉丝列表的结果对象 + * @author binarywang(https://github.com/binarywang) + * Created by Binary Wang on 2016-09-19. + */ +public class WxTagListUser { + + public static WxTagListUser fromJson(String json) { + return WxMpGsonBuilder.create().fromJson(json,WxTagListUser.class); + } + + public String toJson() { + return WxMpGsonBuilder.create().toJson(this); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); + } + + /** + *"count":2,这次获取的粉丝数量 + */ + @SerializedName("count") + private Integer count; + + /** + *"data" 粉丝列表 + */ + @SerializedName("data") + private WxTagListUserData data; + + /** + *"next_openid" 拉取列表最后一个用户的openid + */ + @SerializedName("next_openid") + private String nextOpenid; + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public WxTagListUserData getData() { + return data; + } + + public void setData(WxTagListUserData data) { + this.data = data; + } + + public String getNextOpenid() { + return nextOpenid; + } + + public void setNextOpenid(String nextOpenid) { + this.nextOpenid = nextOpenid; + } + + public static class WxTagListUserData { + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); + } + + /** + * openid 列表 + */ + @SerializedName("openid") + private List openidList; + + public List getOpenidList() { + return openidList; + } + + public void setOpenidList(List openidList) { + this.openidList = openidList; + } + } +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java index 6471b88c..60ab3780 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java @@ -1,15 +1,14 @@ package me.chanjar.weixin.mp.api.impl; -import java.util.List; - +import com.google.inject.Inject; +import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.bean.tag.WxTagListUser; +import me.chanjar.weixin.mp.bean.tag.WxUserTag; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import com.google.inject.Inject; - -import me.chanjar.weixin.mp.api.ApiTestModule; -import me.chanjar.weixin.mp.bean.tag.WxUserTag; +import java.util.List; /** * @@ -22,7 +21,7 @@ public class WxMpUserTagServiceImplTest { @Inject protected WxMpServiceImpl wxService; - private Integer tagId; + private Integer tagId = 2; @Test public void testTagCreate() throws Exception { @@ -55,4 +54,10 @@ public class WxMpUserTagServiceImplTest { Assert.assertTrue(res); } -} \ No newline at end of file + @Test + public void testTagListUser() throws Exception { + WxTagListUser res = this.wxService.getUserTagService().tagListUser(this.tagId, null); + System.out.println(res); + Assert.assertNotNull(res); + } +}