@@ -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; | |||
/** | |||
* <pre> | |||
* 获取标签下粉丝列表 | |||
* 详情请见:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">用户标签管理</a> | |||
* 接口url格式: https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=ACCESS_TOKEN | |||
* </pre> | |||
* | |||
*/ | |||
WxTagListUser tagListUser(Integer tagId, String nextOpenid) throws WxErrorException; | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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<String> openidList; | |||
public List<String> getOpenidList() { | |||
return openidList; | |||
} | |||
public void setOpenidList(List<String> openidList) { | |||
this.openidList = openidList; | |||
} | |||
} | |||
} |
@@ -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); | |||
} | |||
} | |||
@Test | |||
public void testTagListUser() throws Exception { | |||
WxTagListUser res = this.wxService.getUserTagService().tagListUser(this.tagId, null); | |||
System.out.println(res); | |||
Assert.assertNotNull(res); | |||
} | |||
} |