From b205b7bff259399a535dc40150ba90ec0732ed18 Mon Sep 17 00:00:00 2001 From: ukid Date: Thu, 21 May 2015 13:21:00 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9js=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E6=89=80=E9=9C=80=E5=8F=82=E6=95=B0=EF=BC=8C=E5=8E=BB=E6=8E=89?= =?UTF-8?q?jsapiTicket,=E5=A2=9E=E5=8A=A0appid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/common/bean/WxJsapiSignature.java | 21 +++++++++---------- .../weixin/mp/api/WxMpServiceImpl.java | 1 + 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java index af32310a..886fd360 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java @@ -6,11 +6,10 @@ import java.io.Serializable; * jspai signature */ public class WxJsapiSignature implements Serializable { - + private String appid; + private String noncestr; - private String jsapiTicket; - private long timestamp; private String url; @@ -33,14 +32,6 @@ public class WxJsapiSignature implements Serializable { this.noncestr = noncestr; } - public String getJsapiTicket() { - return jsapiTicket; - } - - public void setJsapiTicket(String jsapiTicket) { - this.jsapiTicket = jsapiTicket; - } - public long getTimestamp() { return timestamp; } @@ -57,4 +48,12 @@ public class WxJsapiSignature implements Serializable { this.url = url; } + public String getAppid() { + return appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index 1e08a69f..fcad2d86 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -164,6 +164,7 @@ public class WxMpServiceImpl implements WxMpService { "url=" + url ); WxJsapiSignature jsapiSignature = new WxJsapiSignature(); + jsapiSignature.setAppid(wxMpConfigStorage.getAppId()); jsapiSignature.setTimestamp(timestamp); jsapiSignature.setNoncestr(noncestr); jsapiSignature.setUrl(url); From b27798209b0c3b139aab6194e7e6dbb1d12253ef Mon Sep 17 00:00:00 2001 From: ukid Date: Fri, 22 May 2015 10:50:25 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7=E6=94=AF=E4=BB=98=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/WxMpService.java | 9 +- .../weixin/mp/api/WxMpServiceImpl.java | 44 ++++ .../weixin/mp/bean/result/WxMpPayResult.java | 215 ++++++++++++++++++ .../mp/bean/result/WxMpPrepayIdResult.java | 5 +- 4 files changed, 269 insertions(+), 4 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 45de6f8c..c2db2689 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -543,7 +543,7 @@ public interface WxMpService { void setMaxRetryTimes(int maxRetryTimes); /** - * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1) + * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" * @param openId 支付人openId * @param outTradeNo 商户端对应订单号 @@ -570,4 +570,11 @@ public interface WxMpService { */ Map getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl); + /** + * 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。 + * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 + * @param transactionId + * @param outTradeNo + */ + WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index fcad2d86..c676570a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -705,4 +705,48 @@ public class WxMpServiceImpl implements WxMpService { payInfo.put("sign", finalSign); return payInfo; } + + @Override + public WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo) { + String nonce_str = System.currentTimeMillis() + ""; + + SortedMap packageParams = new TreeMap(); + packageParams.put("appid", wxMpConfigStorage.getAppId()); + packageParams.put("mch_id", wxMpConfigStorage.getPartnerId()); + packageParams.put("transaction_id", transactionId); + packageParams.put("out_trade_no", outTradeNo); + packageParams.put("nonce_str", nonce_str); + + String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey()); + String xml = "" + + "" + wxMpConfigStorage.getAppId() + "" + + "" + wxMpConfigStorage.getPartnerId() + "" + + "" + transactionId + "" + + "" + outTradeNo + "" + + "" + nonce_str + "" + + "" + sign + "" + + ""; + + HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery"); + if (httpProxy != null) { + RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build(); + httpPost.setConfig(config); + } + + StringEntity entity = new StringEntity(xml, Consts.UTF_8); + httpPost.setEntity(entity); + try { + CloseableHttpResponse response = httpClient.execute(httpPost); + String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); + XStream xstream = XStreamInitializer.getInstance(); + xstream.alias("xml", WxMpPayResult.class); + WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent); + return wxMpPayResult; + } catch (IOException e) { + e.printStackTrace(); + } + return new WxMpPayResult(); + } + + } 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 new file mode 100644 index 00000000..7fd850fb --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java @@ -0,0 +1,215 @@ +package me.chanjar.weixin.mp.bean.result; + +import java.io.Serializable; + +/** + *
+ * 查询订单支付状态返回的结果
+ * 
+ * 查询订单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2)
+ *
+ * 
+ * + * @author ukid + */ +public class WxMpPayResult implements Serializable { + private String return_code; + private String return_msg; + private String appid; + private String mch_id; + private String nonce_str; + private String sign; + private String result_code; + private String err_code; + private String err_code_des; + private String trade_state; + private String device_info; + private String openid; + private String is_subscribe; + private String trade_type; + private String bank_type; + private String total_fee; + private String coupon_fee; + private String fee_type; + private String transaction_id; + private String out_trade_no; + private String attach; + private String time_end; + + public String getReturn_code() { + return return_code; + } + + public String getReturn_msg() { + return return_msg; + } + + public String getAppid() { + return appid; + } + + public String getMch_id() { + return mch_id; + } + + public String getNonce_str() { + return nonce_str; + } + + public String getSign() { + return sign; + } + + public String getResult_code() { + return result_code; + } + + public String getErr_code() { + return err_code; + } + + public String getErr_code_des() { + return err_code_des; + } + + public String getTrade_state() { + return trade_state; + } + + public String getDevice_info() { + return device_info; + } + + public String getOpenid() { + return openid; + } + + public String getIs_subscribe() { + return is_subscribe; + } + + public String getTrade_type() { + return trade_type; + } + + public String getBank_type() { + return bank_type; + } + + public String getTotal_fee() { + return total_fee; + } + + public String getCoupon_fee() { + return coupon_fee; + } + + public String getFee_type() { + return fee_type; + } + + public String getTransaction_id() { + return transaction_id; + } + + public String getOut_trade_no() { + return out_trade_no; + } + + public String getAttach() { + return attach; + } + + public String getTime_end() { + return time_end; + } + + public void setReturn_code(String return_code) { + this.return_code = return_code; + } + + public void setReturn_msg(String return_msg) { + this.return_msg = return_msg; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public void setMch_id(String mch_id) { + this.mch_id = mch_id; + } + + public void setNonce_str(String nonce_str) { + this.nonce_str = nonce_str; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public void setResult_code(String result_code) { + this.result_code = result_code; + } + + public void setErr_code(String err_code) { + this.err_code = err_code; + } + + public void setErr_code_des(String err_code_des) { + this.err_code_des = err_code_des; + } + + public void setTrade_state(String trade_state) { + this.trade_state = trade_state; + } + + public void setDevice_info(String device_info) { + this.device_info = device_info; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public void setIs_subscribe(String is_subscribe) { + this.is_subscribe = is_subscribe; + } + + public void setTrade_type(String trade_type) { + this.trade_type = trade_type; + } + + public void setBank_type(String bank_type) { + this.bank_type = bank_type; + } + + public void setTotal_fee(String total_fee) { + this.total_fee = total_fee; + } + + public void setCoupon_fee(String coupon_fee) { + this.coupon_fee = coupon_fee; + } + + public void setFee_type(String fee_type) { + this.fee_type = fee_type; + } + + public void setTransaction_id(String transaction_id) { + this.transaction_id = transaction_id; + } + + public void setOut_trade_no(String out_trade_no) { + this.out_trade_no = out_trade_no; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public void setTime_end(String time_end) { + this.time_end = time_end; + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java index 25286168..aa42299a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java @@ -4,10 +4,9 @@ import java.io.Serializable; /** *
- * 群发消息一发送就返回的结果
+ * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果
  *
- * 真正的群发消息是否发送成功要看
- * http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口#.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81.E7.BE.A4.E5.8F.91.E7.BB.93.E6.9E.9C
+ * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
  *
  * 
* From 8eb028ffb431b8612e8fe1fb8cfed4049ab9da63 Mon Sep 17 00:00:00 2001 From: ukid Date: Fri, 22 May 2015 11:20:43 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83=E5=86=85=E5=AE=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/WxMpService.java | 8 + .../weixin/mp/api/WxMpServiceImpl.java | 13 + .../mp/bean/result/WxMpPayCallback.java | 260 ++++++++++++++++++ 3 files changed, 281 insertions(+) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index c2db2689..29f1a46f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -577,4 +577,12 @@ public interface WxMpService { * @param outTradeNo */ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo); + + /** + * 读取支付结果通知 + * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 + * @param xmlData + * @return + */ + WxMpPayCallback getJSSDKCallbackData(String xmlData); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index c676570a..75b6d31b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -747,6 +747,19 @@ public class WxMpServiceImpl implements WxMpService { } return new WxMpPayResult(); } + + @Override + public WxMpPayCallback getJSSDKCallbackData(String xmlData) { + try { + XStream xstream = XStreamInitializer.getInstance(); + xstream.alias("xml", WxMpPayResult.class); + WxMpPayCallback wxMpCallback = (WxMpPayCallback) xstream.fromXML(xmlData); + return wxMpCallback; + } catch (Exception e){ + e.printStackTrace(); + } + return new WxMpPayCallback(); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java new file mode 100644 index 00000000..a65603c4 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java @@ -0,0 +1,260 @@ +package me.chanjar.weixin.mp.bean.result; + +import java.io.Serializable; + +/** + * pre> 订单支付状态回调 + * + * 支付结果通知(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7) + * + * /pre> + * + * @author ukid + */ +public class WxMpPayCallback implements Serializable { + private String return_code; + private String return_msg; + + private String appid; + private String mch_id; + private String device_info; + private String nonce_str; + private String sign; + private String result_code; + private String err_code; + private String err_code_des; + private String openid; + private String is_subscribe; + private String trade_type; + private String bank_type; + private String total_fee; + private String fee_type; + private String cash_fee; + private String cash_fee_type; + private String coupon_fee; + private String coupon_count; + private String coupon_batch_id_$n; + private String coupon_id_$n; + private String coupon_fee_$n; + private String transaction_id; + private String out_trade_no; + private String attach; + private String time_end; + + public String getReturn_code() { + return return_code; + } + + public String getReturn_msg() { + return return_msg; + } + + public String getAppid() { + return appid; + } + + public String getMch_id() { + return mch_id; + } + + public String getDevice_info() { + return device_info; + } + + public String getNonce_str() { + return nonce_str; + } + + public String getSign() { + return sign; + } + + public String getResult_code() { + return result_code; + } + + public String getErr_code() { + return err_code; + } + + public String getErr_code_des() { + return err_code_des; + } + + public String getOpenid() { + return openid; + } + + public String getIs_subscribe() { + return is_subscribe; + } + + public String getTrade_type() { + return trade_type; + } + + public String getBank_type() { + return bank_type; + } + + public String getTotal_fee() { + return total_fee; + } + + public String getFee_type() { + return fee_type; + } + + public String getCash_fee() { + return cash_fee; + } + + public String getCash_fee_type() { + return cash_fee_type; + } + + public String getCoupon_fee() { + return coupon_fee; + } + + public String getCoupon_count() { + return coupon_count; + } + + public String getCoupon_batch_id_$n() { + return coupon_batch_id_$n; + } + + public String getCoupon_id_$n() { + return coupon_id_$n; + } + + public String getCoupon_fee_$n() { + return coupon_fee_$n; + } + + public String getTransaction_id() { + return transaction_id; + } + + public String getOut_trade_no() { + return out_trade_no; + } + + public String getAttach() { + return attach; + } + + public String getTime_end() { + return time_end; + } + + public void setReturn_code(String return_code) { + this.return_code = return_code; + } + + public void setReturn_msg(String return_msg) { + this.return_msg = return_msg; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public void setMch_id(String mch_id) { + this.mch_id = mch_id; + } + + public void setDevice_info(String device_info) { + this.device_info = device_info; + } + + public void setNonce_str(String nonce_str) { + this.nonce_str = nonce_str; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public void setResult_code(String result_code) { + this.result_code = result_code; + } + + public void setErr_code(String err_code) { + this.err_code = err_code; + } + + public void setErr_code_des(String err_code_des) { + this.err_code_des = err_code_des; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public void setIs_subscribe(String is_subscribe) { + this.is_subscribe = is_subscribe; + } + + public void setTrade_type(String trade_type) { + this.trade_type = trade_type; + } + + public void setBank_type(String bank_type) { + this.bank_type = bank_type; + } + + public void setTotal_fee(String total_fee) { + this.total_fee = total_fee; + } + + public void setFee_type(String fee_type) { + this.fee_type = fee_type; + } + + public void setCash_fee(String cash_fee) { + this.cash_fee = cash_fee; + } + + public void setCash_fee_type(String cash_fee_type) { + this.cash_fee_type = cash_fee_type; + } + + public void setCoupon_fee(String coupon_fee) { + this.coupon_fee = coupon_fee; + } + + public void setCoupon_count(String coupon_count) { + this.coupon_count = coupon_count; + } + + public void setCoupon_batch_id_$n(String coupon_batch_id_$n) { + this.coupon_batch_id_$n = coupon_batch_id_$n; + } + + public void setCoupon_id_$n(String coupon_id_$n) { + this.coupon_id_$n = coupon_id_$n; + } + + public void setCoupon_fee_$n(String coupon_fee_$n) { + this.coupon_fee_$n = coupon_fee_$n; + } + + public void setTransaction_id(String transaction_id) { + this.transaction_id = transaction_id; + } + + public void setOut_trade_no(String out_trade_no) { + this.out_trade_no = out_trade_no; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public void setTime_end(String time_end) { + this.time_end = time_end; + } + +} From c6d0f18a4cb30acd9da26aac18456b51bf3fc2e0 Mon Sep 17 00:00:00 2001 From: Daniel Qian Date: Mon, 27 Jul 2015 13:17:21 +0800 Subject: [PATCH 04/19] upgrade to 1.2.1-SNAPSHOT --- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 91984e07..53fd372c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 me.chanjar weixin-java-parent - 1.2.0 + 1.2.1-SNAPSHOT pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 9f03d3a6..f43efd03 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ me.chanjar weixin-java-parent - 1.2.0 + 1.2.1-SNAPSHOT weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 73727ced..e13e1664 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ me.chanjar weixin-java-parent - 1.2.0 + 1.2.1-SNAPSHOT weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 81e3b941..1f4e7142 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ me.chanjar weixin-java-parent - 1.2.0 + 1.2.1-SNAPSHOT weixin-java-mp WeiXin Java Tools - MP From 49a4ab6a6e38cf6e6f4dafc6b1c0a69c1ccc74bb Mon Sep 17 00:00:00 2001 From: codepiano Date: Mon, 27 Jul 2015 22:28:05 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B0=B8=E4=B9=85?= =?UTF-8?q?=E7=B4=A0=E6=9D=90=E7=9B=B8=E5=85=B3=E6=96=B9=E6=B3=95=E5=88=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=AD=EF=BC=8C=E4=BC=98=E5=8C=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/WxMpService.java | 175 +++++++++++++++--- .../weixin/mp/api/WxMpServiceImpl.java | 5 +- .../weixin/mp/api/WxMpMaterialAPITest.java | 2 +- 3 files changed, 156 insertions(+), 26 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 29f1a46f..7b577d6c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -47,9 +47,9 @@ public interface WxMpService { *
    * 获取access_token,本方法线程安全
    * 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
-   * 
+   *
    * 另:本service的所有方法都会在access_token过期是调用此方法
-   * 
+   *
    * 程序员在非必要情况下尽量不要主动调用此方法
 
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
@@ -111,6 +111,135 @@ public interface WxMpService {
    */
   public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException;
 
+  /**
+   * 
+   * 上传非图文永久素材
+   *
+   * 上传的多媒体文件有格式和大小限制,如下:
+   *   图片(image): 图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式
+   *   语音(voice):语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式
+   *   视频(video):在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON
+   *   缩略图(thumb):文档未说明
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
+   * 
+ * @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts} + * @param material 上传的素材, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterial} + * @return + * @throws WxErrorException + */ + public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException; + + /** + *
+   * 上传永久图文素材
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
+   * 
+ * @param news 上传的图文消息, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialNews} + * @return + * @throws WxErrorException + */ + public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws WxErrorException; + + /** + *
+   * 下载声音或者图片永久素材
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+   * 
+ * @param media_id 永久素材的id + * @return + * @throws WxErrorException + */ + public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException; + + /** + *
+   * 获取视频永久素材的信息和下载地址
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+   * 
+ * @param media_id 永久素材的id + * @return + * @throws WxErrorException + */ + public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException; + + /** + *
+   * 获取图文永久素材的信息
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+   * 
+ * @param media_id 永久素材的id + * @return + * @throws WxErrorException + */ + public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException; + + /** + *
+   * 更新图文永久素材
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
+   * 
+ * @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate} + * @return + * @throws WxErrorException + */ + public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException; + + /** + *
+   * 删除永久素材
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/5/e66f61c303db51a6c0f90f46b15af5f5.html
+   * 
+ * @param media_id 永久素材的id + * @return + * @throws WxErrorException + */ + public boolean materialDelete(String media_id) throws WxErrorException; + + /** + *
+   * 获取各类素材总数
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/16/8cc64f8c189674b421bee3ed403993b8.html
+   * 
+ * @return + * @throws WxErrorException + */ + public WxMpMaterialCountResult materialCount() throws WxErrorException; + + /** + *
+   * 分页获取图文素材列表
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
+   * 
+ * @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回 + * @param count 返回素材的数量,取值在1到20之间 + * @return + * @throws WxErrorException + */ + public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException; + + /** + *
+   * 分页获取其他媒体素材列表
+   *
+   * 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
+   * 
+ * @param type 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts} + * @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回 + * @param count 返回素材的数量,取值在1到20之间 + * @return + * @throws WxErrorException + */ + public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException; + /** * @see #mediaUpload(String, String, InputStream) * @param mediaType @@ -118,7 +247,7 @@ public interface WxMpService { * @throws WxErrorException */ public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException; - + /** *
    * 下载多媒体文件
@@ -130,7 +259,7 @@ public interface WxMpService {
    * @throws WxErrorException
    */
   public File mediaDownload(String media_id) throws WxErrorException;
-  
+
   /**
    * 
    * 发送客服消息
@@ -140,11 +269,11 @@ public interface WxMpService {
    * @throws WxErrorException
    */
   public void customMessageSend(WxMpCustomMessage message) throws WxErrorException;
-  
+
   /**
    * 
-   * 上传群发用的图文消息,上传后才能群发图文消息 
-   * 
+   * 上传群发用的图文消息,上传后才能群发图文消息
+   *
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
    * 
* @param news @@ -153,7 +282,7 @@ public interface WxMpService { * @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage) */ public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException; - + /** *
    * 上传群发用的视频,上传后才能群发视频消息
@@ -175,10 +304,10 @@ public interface WxMpService {
    * 
* @param message * @throws WxErrorException - * @return + * @return */ public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException; - + /** *
    * 按openId列表群发消息
@@ -201,7 +330,7 @@ public interface WxMpService {
    * @throws WxErrorException
    */
   public void menuCreate(WxMenu menu) throws WxErrorException;
-  
+
   /**
    * 
    * 自定义菜单删除接口
@@ -210,7 +339,7 @@ public interface WxMpService {
    * @throws WxErrorException
    */
   public void menuDelete() throws WxErrorException;
-  
+
   /**
    * 
    * 自定义菜单查询接口
@@ -227,11 +356,11 @@ public interface WxMpService {
    * 最多支持创建500个分组
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
    * 
- * @param name 分组名字(30个字符以内) + * @param name 分组名字(30个字符以内) * @throws WxErrorException */ public WxMpGroup groupCreate(String name) throws WxErrorException; - + /** *
    * 分组管理接口 - 查询所有分组
@@ -241,34 +370,34 @@ public interface WxMpService {
    * @throws WxErrorException
    */
   public List groupGet() throws WxErrorException;
-  
+
   /**
    * 
    * 分组管理接口 - 查询用户所在分组
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
    * 
- * @param openid 微信用户的openid + * @param openid 微信用户的openid * @throws WxErrorException */ public long userGetGroup(String openid) throws WxErrorException; - + /** *
    * 分组管理接口 - 修改分组名
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
-   * 
+   *
    * 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
    * 
- * @param group 要更新的group,group的id,name必须设置 + * @param group 要更新的group,group的id,name必须设置 * @throws WxErrorException */ public void groupUpdate(WxMpGroup group) throws WxErrorException; - + /** *
    * 分组管理接口 - 移动用户分组
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
-   * 
+   *
    * 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
    * 
* @param openid 用户openid @@ -294,7 +423,7 @@ public interface WxMpService { * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息 *
* @param openid 用户openid - * @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语 + * @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语 * @return * @throws WxErrorException */ @@ -577,7 +706,7 @@ public interface WxMpService { * @param outTradeNo */ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo); - + /** * 读取支付结果通知 * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index 772b06f8..555b4563 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -8,6 +8,7 @@ import com.google.gson.internal.Streams; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.thoughtworks.xstream.XStream; +import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxMenu; @@ -272,10 +273,10 @@ public class WxMpServiceImpl implements WxMpService { } } - public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(String type, int offset, int count) throws WxErrorException { + public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"; Map params = new HashMap(); - params.put("type", type); + params.put("type", WxConsts.MATERIAL_NEWS); params.put("offset", offset); params.put("count", count); String responseText = post(url, new Gson().toJson(params)); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java index bddc864f..f565625b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java @@ -195,7 +195,7 @@ public class WxMpMaterialAPITest { @Test(dependsOnMethods = {"testUpdateNewsInfo"}) public void testMaterialNewsList() throws WxErrorException { - WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(WxConsts.MATERIAL_NEWS, 0, 20); + WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(0, 20); return; } From 4da11fcd74329bc8ebb473104dc77bcab98365a2 Mon Sep 17 00:00:00 2001 From: codepiano Date: Wed, 29 Jul 2015 20:41:42 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E4=BD=BF=E7=94=A8java1.7=E6=96=B0?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=EF=BC=8C=E6=94=B9=E8=BF=9B=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/WxMpServiceImpl.java | 10 +++++----- .../util/http/MaterialDeleteRequestExecutor.java | 6 +++--- .../util/http/MaterialNewsInfoRequestExecutor.java | 6 +++--- .../util/http/MaterialUploadRequestExecutor.java | 4 ++-- .../http/MaterialVideoInfoRequestExecutor.java | 6 +++--- ...terialVoiceAndImageDownloadRequestExecutor.java | 8 ++++---- .../json/WxMpMaterialFileBatchGetGsonAdapter.java | 2 +- .../json/WxMpMaterialNewsBatchGetGsonAdapter.java | 2 +- .../chanjar/weixin/mp/api/WxMpMaterialAPITest.java | 14 +++++++------- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index 555b4563..f688265f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -1,6 +1,5 @@ package me.chanjar.weixin.mp.api; -import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -24,6 +23,7 @@ import me.chanjar.weixin.common.util.crypto.WxCryptUtil; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.http.*; import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.bean.*; import me.chanjar.weixin.mp.bean.result.*; @@ -275,11 +275,11 @@ public class WxMpServiceImpl implements WxMpService { public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"; - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("type", WxConsts.MATERIAL_NEWS); params.put("offset", offset); params.put("count", count); - String responseText = post(url, new Gson().toJson(params)); + String responseText = post(url, WxGsonBuilder.create().toJson(params)); WxError wxError = WxError.fromJson(responseText); if (wxError.getErrorCode() == 0) { return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialNewsBatchGetResult.class); @@ -290,11 +290,11 @@ public class WxMpServiceImpl implements WxMpService { public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"; - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("type", type); params.put("offset", offset); params.put("count", count); - String responseText = post(url, new Gson().toJson(params)); + String responseText = post(url, WxGsonBuilder.create().toJson(params)); WxError wxError = WxError.fromJson(responseText); if (wxError.getErrorCode() == 0) { return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialFileBatchGetResult.class); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java index 4da3417a..8e7c41de 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.util.http; -import com.google.gson.Gson; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import org.apache.http.HttpHost; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; @@ -31,9 +31,9 @@ public class MaterialDeleteRequestExecutor implements RequestExecutor params = new HashMap(); + Map params = new HashMap<>(); params.put("media_id", materialId); - httpPost.setEntity(new StringEntity(new Gson().toJson(params))); + httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); CloseableHttpResponse response = httpclient.execute(httpPost); String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); WxError error = WxError.fromJson(responseContent); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java index 9cae8268..e23ecc50 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.util.http; -import com.google.gson.Gson; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.WxMpMaterialNews; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import org.apache.http.HttpHost; @@ -32,9 +32,9 @@ public class MaterialNewsInfoRequestExecutor implements RequestExecutor params = new HashMap(); + Map params = new HashMap<>(); params.put("media_id", materialId); - httpPost.setEntity(new StringEntity(new Gson().toJson(params))); + httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); CloseableHttpResponse response = httpclient.execute(httpPost); String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); WxError error = WxError.fromJson(responseContent); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java index 2d922614..63d92523 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.util.http; -import com.google.gson.Gson; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.WxMpMaterial; import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult; import org.apache.http.HttpHost; @@ -39,7 +39,7 @@ public class MaterialUploadRequestExecutor implements RequestExecutor form = material.getForm(); if (material.getForm() != null) { - multipartEntityBuilder.addTextBody("description", new Gson().toJson(form)); + multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form)); } httpPost.setEntity(multipartEntityBuilder.build()); httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java index f097eaef..e529f4e7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.util.http; -import com.google.gson.Gson; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult; import org.apache.http.HttpHost; import org.apache.http.client.ClientProtocolException; @@ -31,9 +31,9 @@ public class MaterialVideoInfoRequestExecutor implements RequestExecutor params = new HashMap(); + Map params = new HashMap<>(); params.put("media_id", materialId); - httpPost.setEntity(new StringEntity(new Gson().toJson(params))); + httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); CloseableHttpResponse response = httpclient.execute(httpPost); String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); WxError error = WxError.fromJson(responseContent); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java index 1c7e8639..72917a93 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.util.http; -import com.google.gson.Gson; import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; import org.apache.commons.io.IOUtils; import org.apache.http.HttpHost; import org.apache.http.client.ClientProtocolException; @@ -41,9 +41,9 @@ public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExec httpPost.setConfig(config); } - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("media_id", materialId); - httpPost.setEntity(new StringEntity(new Gson().toJson(params))); + httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); CloseableHttpResponse response = httpclient.execute(httpPost); // 下载媒体文件出错 InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response); @@ -51,7 +51,7 @@ public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExec String responseContentString = new String(responseContent, "UTF-8"); if (responseContentString.length() < 100) { try { - WxError wxError = new Gson().fromJson(responseContentString, WxError.class); + WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java index 5483068f..74e3edad 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java @@ -29,7 +29,7 @@ public class WxMpMaterialFileBatchGetGsonAdapter implements JsonDeserializer items = new ArrayList(); + List items = new ArrayList<>(); for (JsonElement anItem : item) { JsonObject articleInfo = anItem.getAsJsonObject(); items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem.class)); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsBatchGetGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsBatchGetGsonAdapter.java index e78a1586..eed1610b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsBatchGetGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsBatchGetGsonAdapter.java @@ -29,7 +29,7 @@ public class WxMpMaterialNewsBatchGetGsonAdapter implements JsonDeserializer items = new ArrayList(); + List items = new ArrayList<>(); for (JsonElement anItem : item) { JsonObject articleInfo = anItem.getAsJsonObject(); items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class)); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java index f565625b..8e145e15 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java @@ -31,7 +31,7 @@ public class WxMpMaterialAPITest { @Inject protected WxMpServiceImpl wxService; - private Map> media_ids = new LinkedHashMap>(); + private Map> media_ids = new LinkedHashMap<>(); // 缩略图的id,测试上传图文使用 private String thumbMediaId = ""; // 单图文消息media_id @@ -64,7 +64,7 @@ public class WxMpMaterialAPITest { thumbMediaId = res.getMediaId(); } - Map materialInfo = new HashMap(); + Map materialInfo = new HashMap<>(); materialInfo.put("media_id", res.getMediaId()); materialInfo.put("length", tempFile.length()); materialInfo.put("filename", tempFile.getName()); @@ -217,8 +217,8 @@ public class WxMpMaterialAPITest { public Object[][] downloadMaterial() { Object[][] params = new Object[this.media_ids.size()][]; int index = 0; - for (Iterator iterator = this.media_ids.keySet().iterator(); iterator.hasNext(); ) { - params[index] = new Object[]{iterator.next()}; + for (String mediaId : this.media_ids.keySet()) { + params[index] = new Object[]{mediaId}; index++; } return params; @@ -226,9 +226,9 @@ public class WxMpMaterialAPITest { @DataProvider public Iterator allTestMaterial() { - List params = new ArrayList(); - for (Iterator iterator = this.media_ids.keySet().iterator(); iterator.hasNext(); ) { - params.add(new Object[]{iterator.next()}); + List params = new ArrayList<>(); + for (String mediaId : this.media_ids.keySet()) { + params.add(new Object[]{mediaId}); } params.add(new Object[]{this.singleNewsMediaId}); params.add(new Object[]{this.multiNewsMediaId}); From ce109695e79d21dd0a1cbe1ef3a343c2bcb71f01 Mon Sep 17 00:00:00 2001 From: ssls Date: Mon, 3 Aug 2015 17:09:44 +0800 Subject: [PATCH 07/19] --- .../chanjar/weixin/common/api/WxConsts.java | 1 + .../weixin/mp/bean/WxMpXmlOutMessage.java | 8 ++++ ...pXmlOutTransferCustomerServiceMessage.java | 41 +++++++++++++++++++ .../TransferCustomerServiceBuilder.java | 19 +++++++++ 4 files changed, 69 insertions(+) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java index 454c6f23..80d16638 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java @@ -29,6 +29,7 @@ public class WxConsts { public static final String CUSTOM_MSG_MUSIC = "music"; public static final String CUSTOM_MSG_NEWS = "news"; public static final String CUSTOM_MSG_FILE = "file"; + public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service"; /////////////////////// // 群发消息的消息类型 diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java index 370d4430..bca8c143 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java @@ -121,4 +121,12 @@ public abstract class WxMpXmlOutMessage implements Serializable { public static NewsBuilder NEWS() { return new NewsBuilder(); } + /** + * 获得客服消息builder + * + * @return + */ + public static TransferCustomerServiceBuilder TRANSFER_CUSTOMER_SERVICE() { + return new TransferCustomerServiceBuilder(); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java new file mode 100644 index 00000000..5783d2b4 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java @@ -0,0 +1,41 @@ +package me.chanjar.weixin.mp.bean; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamConverter; +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; +import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter; + +@XStreamAlias("xml") +public class WxMpXmlOutTransferCustomerServiceMessage extends WxMpXmlOutMessage { + @XStreamAlias("TransInfo") + protected final TransInfo transInfo = new TransInfo(); + + public WxMpXmlOutTransferCustomerServiceMessage() { + this.msgType = WxConsts.CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE; + } + + public String getKfAccount() { + return transInfo.getKfAccount(); + } + + public void setKfAccount(String kfAccount) { + transInfo.setKfAccount(kfAccount); + } + + @XStreamAlias("TransInfo") + public static class TransInfo { + + @XStreamAlias("KfAccount") + @XStreamConverter(value=XStreamCDataConverter.class) + private String kfAccount; + + public String getKfAccount() { + return kfAccount; + } + + public void setKfAccount(String kfAccount) { + this.kfAccount = kfAccount; + } + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java new file mode 100644 index 00000000..5c4a14a3 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java @@ -0,0 +1,19 @@ +package me.chanjar.weixin.mp.bean.outxmlbuilder; + +import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage; + +/** + * 客服消息builder + *
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.TEXT().content(...).toUser(...).build();
+ * 
+ * + * @author chanjarster + */ +public final class TransferCustomerServiceBuilder extends BaseBuilder { + public WxMpXmlOutTransferCustomerServiceMessage build() { + WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage(); + setCommon(m); + return m; + } +} From cf9ccbc54dae3e90b7f285fb7b5793f39b089515 Mon Sep 17 00:00:00 2001 From: Daniel Qian Date: Mon, 3 Aug 2015 17:30:28 +0800 Subject: [PATCH 08/19] fix: issue #128 --- .../me/chanjar/weixin/cp/api/WxCpServiceImpl.java | 3 +++ .../me/chanjar/weixin/mp/api/WxMpServiceImpl.java | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index 487e0078..48412aaf 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -551,6 +551,9 @@ public class WxCpServiceImpl implements WxCpService { } protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + if (uri.indexOf("access_token=") != -1) { + throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); + } String accessToken = getAccessToken(false); String uriWithAccessToken = uri; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index f688265f..d8faae64 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -349,8 +349,9 @@ public class WxMpServiceImpl implements WxMpService { * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } */ JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); - return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken>() { - }.getType()); + return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), + new TypeToken>() { + }.getType()); } public long userGetGroup(String openid) throws WxErrorException { @@ -597,8 +598,9 @@ public class WxMpServiceImpl implements WxMpService { param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate)); String responseContent = post(url, param.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); - return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken>() { - }.getType()); + return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), + new TypeToken>() { + }.getType()); } public String get(String url, String queryParam) throws WxErrorException { @@ -646,6 +648,9 @@ public class WxMpServiceImpl implements WxMpService { } protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException { + if (uri.indexOf("access_token=") != -1) { + throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); + } String accessToken = getAccessToken(false); String uriWithAccessToken = uri; From f252792e43deaf9eb3c83821cd512ebb9300fc0c Mon Sep 17 00:00:00 2001 From: ssls Date: Tue, 4 Aug 2015 16:17:07 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E9=87=8C=E7=9A=84TEXT=E4=B8=BATRANSFER=5FCUSTOMER=5FSERVICE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java index 5c4a14a3..0fda1ae7 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java @@ -5,7 +5,7 @@ import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage; /** * 客服消息builder *
- * 用法: WxMpCustomMessage m = WxMpCustomMessage.TEXT().content(...).toUser(...).build();
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build();
  * 
* * @author chanjarster From 2942e1e85cd91fadcda09908dfaa2a791ba3f49c Mon Sep 17 00:00:00 2001 From: ssls Date: Tue, 4 Aug 2015 16:33:39 +0800 Subject: [PATCH 10/19] --- .../outxmlbuilder/TransferCustomerServiceBuilder.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java index 0fda1ae7..37616cf9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java @@ -11,9 +11,18 @@ import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage; * @author chanjarster */ public final class TransferCustomerServiceBuilder extends BaseBuilder { + private String kfAccount; + + public TransferCustomerServiceBuilder kfAccount(String kfAccount) { + this.kfAccount = kfAccount; + return this; + } + + public WxMpXmlOutTransferCustomerServiceMessage build() { WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage(); setCommon(m); + m.setKfAccount(kfAccount); return m; } -} +} \ No newline at end of file From acedf39518fb18934bc8a8036c3a5cffeee2e08c Mon Sep 17 00:00:00 2001 From: Daniel Qian Date: Thu, 13 Aug 2015 08:54:18 +0800 Subject: [PATCH 11/19] issue #172 upgrade httpclient to 4.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53fd372c..a7ae7c05 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ UTF-8 true true - 4.3.5 + 4.5 1.7.10 1.1.2 From cf8f2798184d4166fcb3ae5cc5c13d773dfa7c0d Mon Sep 17 00:00:00 2001 From: caosk <339627841@qq.com> Date: Thu, 13 Aug 2015 16:00:05 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=8F=B7=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=A2=9E=E5=8A=A0enable=E5=B1=9E=E6=80=A7=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=90=8C=E6=AD=A5=E6=9C=AC=E5=9C=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=9A=84=E7=94=A8=E6=88=B7=E6=9C=89=E6=95=88=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E5=BE=AE=E4=BF=A1=E5=BC=82=E5=B8=B8=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=8A=A0=E5=86=92=E5=8F=B7=EF=BC=8C=E4=BB=A3=E7=A0=81=E5=B7=B2?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/common/bean/result/WxError.java | 2 +- .../main/java/me/chanjar/weixin/cp/bean/WxCpUser.java | 9 +++++++++ .../chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java index e5123707..740841b9 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java @@ -49,7 +49,7 @@ public class WxError implements Serializable { @Override public String toString() { - return "微信错误 errcode=" + errorCode + ", errmsg=" + errorMsg + "\njson:" + json; + return "微信错误: errcode=" + errorCode + ", errmsg=" + errorMsg + "\njson:" + json; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java index a5c69c01..58b1d5ca 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java @@ -24,6 +24,7 @@ public class WxCpUser implements Serializable { private String weiXinId; private String avatar; private Integer status; + private Integer enable; private final List extAttrs = new ArrayList(); public String getUserId() { @@ -114,6 +115,14 @@ public class WxCpUser implements Serializable { this.status = status; } + public Integer getEnable() { + return enable; + } + + public void setEnable(Integer enable) { + this.enable = enable; + } + public void addExtAttr(String name, String value) { this.extAttrs.add(new Attr(name, value)); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java index 4523ef86..0984644b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java @@ -98,6 +98,9 @@ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSeri if (user.getStatus() != null) { o.addProperty("status", user.getStatus()); } + if (user.getEnable() != null) { + o.addProperty("enable", user.getEnable()); + } if (user.getExtAttrs().size() > 0) { JsonArray attrsJsonArray = new JsonArray(); for (WxCpUser.Attr attr : user.getExtAttrs()) { From ff67476c2840ffb8944bcdcbcf8360dad9c9a7c4 Mon Sep 17 00:00:00 2001 From: ukid Date: Fri, 14 Aug 2015 10:24:23 +0800 Subject: [PATCH 13/19] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95get?= =?UTF-8?q?JSSDKCallbackData=E4=B8=AD=E7=9A=84=E7=B1=BB=E5=9E=8B=E9=94=99?= =?UTF-8?q?=E8=AF=AF=202.=E4=BF=AE=E6=94=B9=E6=94=AF=E4=BB=98=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E6=AE=B5=E5=90=8D=E7=A7=B0=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=9B=B4=E6=8E=A5=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpServiceImpl.java | 86 +++- .../mp/bean/result/WxMpPayCallback.java | 482 +++++++++--------- 2 files changed, 312 insertions(+), 256 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index d8faae64..6e616284 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -1,12 +1,20 @@ package me.chanjar.weixin.mp.api; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.internal.Streams; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.thoughtworks.xstream.XStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.UUID; + import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; @@ -21,14 +29,53 @@ import me.chanjar.weixin.common.util.StringUtils; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.crypto.WxCryptUtil; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.common.util.http.*; +import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.common.util.http.URIUtil; +import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.common.util.xml.XStreamInitializer; -import me.chanjar.weixin.mp.bean.*; -import me.chanjar.weixin.mp.bean.result.*; -import me.chanjar.weixin.mp.util.http.*; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; +import me.chanjar.weixin.mp.bean.WxMpGroup; +import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; +import me.chanjar.weixin.mp.bean.WxMpMassNews; +import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; +import me.chanjar.weixin.mp.bean.WxMpMassVideo; +import me.chanjar.weixin.mp.bean.WxMpMaterial; +import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate; +import me.chanjar.weixin.mp.bean.WxMpMaterialNews; +import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; +import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; +import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; +import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialCountResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialFileBatchGetResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialNewsBatchGetResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult; +import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpPayCallback; +import me.chanjar.weixin.mp.bean.result.WxMpPayResult; +import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult; +import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; +import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; +import me.chanjar.weixin.mp.bean.result.WxMpUser; +import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate; +import me.chanjar.weixin.mp.bean.result.WxMpUserList; +import me.chanjar.weixin.mp.bean.result.WxMpUserSummary; +import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor; +import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; +import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor; +import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor; +import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor; +import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import org.apache.commons.codec.digest.DigestUtils; import org.apache.http.Consts; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; @@ -47,12 +94,13 @@ import org.apache.http.impl.client.HttpClients; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.security.NoSuchAlgorithmException; -import java.util.*; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.internal.Streams; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.thoughtworks.xstream.XStream; public class WxMpServiceImpl implements WxMpService { @@ -796,7 +844,7 @@ public class WxMpServiceImpl implements WxMpService { payInfo.put("signType", "MD5"); String finalSign = WxCryptUtil.createSign(payInfo, wxMpConfigStorage.getPartnerKey()); - payInfo.put("sign", finalSign); + payInfo.put("paySign", finalSign); return payInfo; } @@ -846,7 +894,7 @@ public class WxMpServiceImpl implements WxMpService { public WxMpPayCallback getJSSDKCallbackData(String xmlData) { try { XStream xstream = XStreamInitializer.getInstance(); - xstream.alias("xml", WxMpPayResult.class); + xstream.alias("xml", WxMpPayCallback.class); WxMpPayCallback wxMpCallback = (WxMpPayCallback) xstream.fromXML(xmlData); return wxMpCallback; } catch (Exception e){ diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java index a65603c4..993ebe4e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java @@ -12,249 +12,257 @@ import java.io.Serializable; * @author ukid */ public class WxMpPayCallback implements Serializable { - private String return_code; - private String return_msg; - - private String appid; - private String mch_id; - private String device_info; - private String nonce_str; - private String sign; - private String result_code; - private String err_code; - private String err_code_des; - private String openid; - private String is_subscribe; - private String trade_type; - private String bank_type; - private String total_fee; - private String fee_type; - private String cash_fee; - private String cash_fee_type; - private String coupon_fee; - private String coupon_count; - private String coupon_batch_id_$n; - private String coupon_id_$n; - private String coupon_fee_$n; - private String transaction_id; - private String out_trade_no; - private String attach; - private String time_end; - - public String getReturn_code() { - return return_code; - } - - public String getReturn_msg() { - return return_msg; - } - - public String getAppid() { - return appid; - } - - public String getMch_id() { - return mch_id; - } - - public String getDevice_info() { - return device_info; - } - - public String getNonce_str() { - return nonce_str; - } - - public String getSign() { - return sign; - } - - public String getResult_code() { - return result_code; - } - - public String getErr_code() { - return err_code; - } - - public String getErr_code_des() { - return err_code_des; - } - - public String getOpenid() { - return openid; - } - - public String getIs_subscribe() { - return is_subscribe; - } - - public String getTrade_type() { - return trade_type; - } - - public String getBank_type() { - return bank_type; - } - - public String getTotal_fee() { - return total_fee; - } - - public String getFee_type() { - return fee_type; - } - - public String getCash_fee() { - return cash_fee; - } - - public String getCash_fee_type() { - return cash_fee_type; - } - - public String getCoupon_fee() { - return coupon_fee; - } - - public String getCoupon_count() { - return coupon_count; - } - - public String getCoupon_batch_id_$n() { - return coupon_batch_id_$n; - } - - public String getCoupon_id_$n() { - return coupon_id_$n; - } - - public String getCoupon_fee_$n() { - return coupon_fee_$n; - } - - public String getTransaction_id() { - return transaction_id; - } + private String return_code; + private String return_msg; + + private String appid; + private String mch_id; + private String device_info; + private String nonce_str; + private String sign; + private String result_code; + private String err_code; + private String err_code_des; + private String openid; + private String is_subscribe; + private String trade_type; + private String bank_type; + private String total_fee; + private String fee_type; + private String cash_fee; + private String cash_fee_type; + private String coupon_fee; + private String coupon_count; + private String coupon_batch_id_$n; + private String coupon_id_$n; + private String coupon_fee_$n; + private String transaction_id; + private String out_trade_no; + private String attach; + private String time_end; + + public String getReturn_code() { + return return_code; + } + + public String getReturn_msg() { + return return_msg; + } + + public String getAppid() { + return appid; + } + + public String getMch_id() { + return mch_id; + } + + public String getDevice_info() { + return device_info; + } + + public String getNonce_str() { + return nonce_str; + } + + public String getSign() { + return sign; + } + + public String getResult_code() { + return result_code; + } + + public String getErr_code() { + return err_code; + } + + public String getErr_code_des() { + return err_code_des; + } + + public String getOpenid() { + return openid; + } + + public String getIs_subscribe() { + return is_subscribe; + } + + public String getTrade_type() { + return trade_type; + } + + public String getBank_type() { + return bank_type; + } + + public String getTotal_fee() { + return total_fee; + } + + public String getFee_type() { + return fee_type; + } + + public String getCash_fee() { + return cash_fee; + } + + public String getCash_fee_type() { + return cash_fee_type; + } + + public String getCoupon_fee() { + return coupon_fee; + } + + public String getCoupon_count() { + return coupon_count; + } + + public String getCoupon_batch_id_$n() { + return coupon_batch_id_$n; + } + + public String getCoupon_id_$n() { + return coupon_id_$n; + } + + public String getCoupon_fee_$n() { + return coupon_fee_$n; + } + + public String getTransaction_id() { + return transaction_id; + } - public String getOut_trade_no() { - return out_trade_no; - } + public String getOut_trade_no() { + return out_trade_no; + } - public String getAttach() { - return attach; - } + public String getAttach() { + return attach; + } - public String getTime_end() { - return time_end; - } + public String getTime_end() { + return time_end; + } - public void setReturn_code(String return_code) { - this.return_code = return_code; - } + public void setReturn_code(String return_code) { + this.return_code = return_code; + } - public void setReturn_msg(String return_msg) { - this.return_msg = return_msg; - } + public void setReturn_msg(String return_msg) { + this.return_msg = return_msg; + } - public void setAppid(String appid) { - this.appid = appid; - } + public void setAppid(String appid) { + this.appid = appid; + } - public void setMch_id(String mch_id) { - this.mch_id = mch_id; - } - - public void setDevice_info(String device_info) { - this.device_info = device_info; - } - - public void setNonce_str(String nonce_str) { - this.nonce_str = nonce_str; - } - - public void setSign(String sign) { - this.sign = sign; - } - - public void setResult_code(String result_code) { - this.result_code = result_code; - } - - public void setErr_code(String err_code) { - this.err_code = err_code; - } - - public void setErr_code_des(String err_code_des) { - this.err_code_des = err_code_des; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public void setIs_subscribe(String is_subscribe) { - this.is_subscribe = is_subscribe; - } - - public void setTrade_type(String trade_type) { - this.trade_type = trade_type; - } - - public void setBank_type(String bank_type) { - this.bank_type = bank_type; - } - - public void setTotal_fee(String total_fee) { - this.total_fee = total_fee; - } - - public void setFee_type(String fee_type) { - this.fee_type = fee_type; - } - - public void setCash_fee(String cash_fee) { - this.cash_fee = cash_fee; - } - - public void setCash_fee_type(String cash_fee_type) { - this.cash_fee_type = cash_fee_type; - } - - public void setCoupon_fee(String coupon_fee) { - this.coupon_fee = coupon_fee; - } - - public void setCoupon_count(String coupon_count) { - this.coupon_count = coupon_count; - } - - public void setCoupon_batch_id_$n(String coupon_batch_id_$n) { - this.coupon_batch_id_$n = coupon_batch_id_$n; - } - - public void setCoupon_id_$n(String coupon_id_$n) { - this.coupon_id_$n = coupon_id_$n; - } - - public void setCoupon_fee_$n(String coupon_fee_$n) { - this.coupon_fee_$n = coupon_fee_$n; - } - - public void setTransaction_id(String transaction_id) { - this.transaction_id = transaction_id; - } - - public void setOut_trade_no(String out_trade_no) { - this.out_trade_no = out_trade_no; - } - - public void setAttach(String attach) { - this.attach = attach; - } - - public void setTime_end(String time_end) { - this.time_end = time_end; - } + public void setMch_id(String mch_id) { + this.mch_id = mch_id; + } + + public void setDevice_info(String device_info) { + this.device_info = device_info; + } + + public void setNonce_str(String nonce_str) { + this.nonce_str = nonce_str; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public void setResult_code(String result_code) { + this.result_code = result_code; + } + + public void setErr_code(String err_code) { + this.err_code = err_code; + } + + public void setErr_code_des(String err_code_des) { + this.err_code_des = err_code_des; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public void setIs_subscribe(String is_subscribe) { + this.is_subscribe = is_subscribe; + } + + public void setTrade_type(String trade_type) { + this.trade_type = trade_type; + } + + public void setBank_type(String bank_type) { + this.bank_type = bank_type; + } + + public void setTotal_fee(String total_fee) { + this.total_fee = total_fee; + } + + public void setFee_type(String fee_type) { + this.fee_type = fee_type; + } + + public void setCash_fee(String cash_fee) { + this.cash_fee = cash_fee; + } + + public void setCash_fee_type(String cash_fee_type) { + this.cash_fee_type = cash_fee_type; + } + + public void setCoupon_fee(String coupon_fee) { + this.coupon_fee = coupon_fee; + } + + public void setCoupon_count(String coupon_count) { + this.coupon_count = coupon_count; + } + + public void setCoupon_batch_id_$n(String coupon_batch_id_$n) { + this.coupon_batch_id_$n = coupon_batch_id_$n; + } + + public void setCoupon_id_$n(String coupon_id_$n) { + this.coupon_id_$n = coupon_id_$n; + } + + public void setCoupon_fee_$n(String coupon_fee_$n) { + this.coupon_fee_$n = coupon_fee_$n; + } + + public void setTransaction_id(String transaction_id) { + this.transaction_id = transaction_id; + } + + public void setOut_trade_no(String out_trade_no) { + this.out_trade_no = out_trade_no; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public void setTime_end(String time_end) { + this.time_end = time_end; + } + + @Override + public String toString() { + return "WxMpPayCallback [return_code=" + return_code + ", return_msg=" + return_msg + ", appid=" + appid + ", mch_id=" + mch_id + ", device_info=" + device_info + ", nonce_str=" + nonce_str + ", sign=" + sign + ", result_code=" + result_code + ", err_code=" + err_code + + ", err_code_des=" + err_code_des + ", openid=" + openid + ", is_subscribe=" + is_subscribe + ", trade_type=" + trade_type + ", bank_type=" + bank_type + ", total_fee=" + total_fee + ", fee_type=" + fee_type + ", cash_fee=" + cash_fee + ", cash_fee_type=" + + cash_fee_type + ", coupon_fee=" + coupon_fee + ", coupon_count=" + coupon_count + ", coupon_batch_id_$n=" + coupon_batch_id_$n + ", coupon_id_$n=" + coupon_id_$n + ", coupon_fee_$n=" + coupon_fee_$n + ", transaction_id=" + transaction_id + ", out_trade_no=" + + out_trade_no + ", attach=" + attach + ", time_end=" + time_end + "]"; + } } From 57acfd53307b33cd08a857ef9348c661f40a6c62 Mon Sep 17 00:00:00 2001 From: caosk <339627841@qq.com> Date: Fri, 14 Aug 2015 18:45:13 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=92=8C=E9=83=A8=E9=97=A8=E7=9A=84=E5=85=A8?= =?UTF-8?q?=E9=87=8F=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/cp/api/WxCpService.java | 14 +++++ .../weixin/cp/api/WxCpServiceImpl.java | 57 +++++++++++++------ 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index ac07ea6b..d9ce9edd 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -556,4 +556,18 @@ public interface WxCpService { * @param sessionManager */ void setSessionManager(WxSessionManager sessionManager); + + /** + * 上传部门列表覆盖企业号上的部门信息 + * @param mediaId + * @throws WxErrorException + */ + void replaceParty(String mediaId) throws WxErrorException; + + /** + * 上传用户列表覆盖企业号上的用户信息 + * @param mediaId + * @throws WxErrorException + */ + void replaceUser(String mediaId) throws WxErrorException; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index 48412aaf..1452ed16 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -1,13 +1,14 @@ package me.chanjar.weixin.cp.api; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.gson.internal.Streams; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.sun.media.sound.SoftTuning; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.math.BigDecimal; +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.UUID; + import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxMenu; @@ -21,13 +22,19 @@ import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.StringUtils; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.fs.FileUtils; -import me.chanjar.weixin.common.util.http.*; +import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; +import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.common.util.http.URIUtil; import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.cp.bean.WxCpDepart; import me.chanjar.weixin.cp.bean.WxCpMessage; import me.chanjar.weixin.cp.bean.WxCpTag; import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -43,14 +50,13 @@ import org.apache.http.impl.client.HttpClients; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.math.BigDecimal; -import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.UUID; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import com.google.gson.internal.Streams; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; public class WxCpServiceImpl implements WxCpService { @@ -243,7 +249,6 @@ public class WxCpServiceImpl implements WxCpService { public File mediaDownload(String media_id) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"; - return execute(new MediaDownloadRequestExecutor(wxCpConfigStorage.getTmpDirFile()), url, "media_id=" + media_id); } @@ -650,6 +655,22 @@ public class WxCpServiceImpl implements WxCpService { this.sessionManager = sessionManager; } + @Override + public void replaceParty(String mediaId) throws WxErrorException { + String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty"; + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("media_id", mediaId); + post(url, jsonObject.toString()); + } + + @Override + public void replaceUser(String mediaId) throws WxErrorException { + String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser"; + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("media_id", mediaId); + post(url, jsonObject.toString()); + } + public File getTmpDirFile() { return tmpDirFile; } From afaa0a3bde62212b336a87e7152645beb6633f36 Mon Sep 17 00:00:00 2001 From: caosk <339627841@qq.com> Date: Sat, 15 Aug 2015 20:05:32 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E9=80=9A=E8=AE=AF=E5=BD=95=E5=85=A8=E9=87=8F=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/cp/api/WxCpService.java | 12 ++++++++++-- .../me/chanjar/weixin/cp/api/WxCpServiceImpl.java | 14 ++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index d9ce9edd..63abc79c 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -562,12 +562,20 @@ public interface WxCpService { * @param mediaId * @throws WxErrorException */ - void replaceParty(String mediaId) throws WxErrorException; + String replaceParty(String mediaId) throws WxErrorException; /** * 上传用户列表覆盖企业号上的用户信息 * @param mediaId * @throws WxErrorException */ - void replaceUser(String mediaId) throws WxErrorException; + String replaceUser(String mediaId) throws WxErrorException; + + /** + * 获取异步任务结果 + * @param joinId + * @return + * @throws WxErrorException + */ + String getTaskResult(String joinId) throws WxErrorException; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java index 1452ed16..7b95c32c 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java @@ -656,19 +656,25 @@ public class WxCpServiceImpl implements WxCpService { } @Override - public void replaceParty(String mediaId) throws WxErrorException { + public String replaceParty(String mediaId) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty"; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("media_id", mediaId); - post(url, jsonObject.toString()); + return post(url, jsonObject.toString()); } @Override - public void replaceUser(String mediaId) throws WxErrorException { + public String replaceUser(String mediaId) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser"; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("media_id", mediaId); - post(url, jsonObject.toString()); + return post(url, jsonObject.toString()); + } + + @Override + public String getTaskResult(String joinId) throws WxErrorException { + String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid="+joinId; + return get(url, null); } public File getTmpDirFile() { From 6ede883f71659c105b1acfa78f425244b4e068a7 Mon Sep 17 00:00:00 2001 From: ukid Date: Wed, 19 Aug 2015 18:36:06 +0800 Subject: [PATCH 16/19] format with spaces --- .../mp/bean/result/WxMpPayCallback.java | 501 +++++++++--------- 1 file changed, 256 insertions(+), 245 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java index 993ebe4e..18aeda4d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java @@ -12,257 +12,268 @@ import java.io.Serializable; * @author ukid */ public class WxMpPayCallback implements Serializable { - private String return_code; - private String return_msg; - - private String appid; - private String mch_id; - private String device_info; - private String nonce_str; - private String sign; - private String result_code; - private String err_code; - private String err_code_des; - private String openid; - private String is_subscribe; - private String trade_type; - private String bank_type; - private String total_fee; - private String fee_type; - private String cash_fee; - private String cash_fee_type; - private String coupon_fee; - private String coupon_count; - private String coupon_batch_id_$n; - private String coupon_id_$n; - private String coupon_fee_$n; - private String transaction_id; - private String out_trade_no; - private String attach; - private String time_end; - - public String getReturn_code() { - return return_code; - } - - public String getReturn_msg() { - return return_msg; - } - - public String getAppid() { - return appid; - } - - public String getMch_id() { - return mch_id; - } - - public String getDevice_info() { - return device_info; - } - - public String getNonce_str() { - return nonce_str; - } - - public String getSign() { - return sign; - } - - public String getResult_code() { - return result_code; - } - - public String getErr_code() { - return err_code; - } - - public String getErr_code_des() { - return err_code_des; - } - - public String getOpenid() { - return openid; - } - - public String getIs_subscribe() { - return is_subscribe; - } - - public String getTrade_type() { - return trade_type; - } - - public String getBank_type() { - return bank_type; - } - - public String getTotal_fee() { - return total_fee; - } - - public String getFee_type() { - return fee_type; - } - - public String getCash_fee() { - return cash_fee; - } - - public String getCash_fee_type() { - return cash_fee_type; - } - - public String getCoupon_fee() { - return coupon_fee; - } - - public String getCoupon_count() { - return coupon_count; - } - - public String getCoupon_batch_id_$n() { - return coupon_batch_id_$n; - } - - public String getCoupon_id_$n() { - return coupon_id_$n; - } - - public String getCoupon_fee_$n() { - return coupon_fee_$n; - } - - public String getTransaction_id() { - return transaction_id; - } + private String return_code; + private String return_msg; + + private String appid; + private String mch_id; + private String device_info; + private String nonce_str; + private String sign; + private String result_code; + private String err_code; + private String err_code_des; + private String openid; + private String is_subscribe; + private String trade_type; + private String bank_type; + private String total_fee; + private String fee_type; + private String cash_fee; + private String cash_fee_type; + private String coupon_fee; + private String coupon_count; + private String coupon_batch_id_$n; + private String coupon_id_$n; + private String coupon_fee_$n; + private String transaction_id; + private String out_trade_no; + private String attach; + private String time_end; + + public String getReturn_code() { + return return_code; + } + + public String getReturn_msg() { + return return_msg; + } + + public String getAppid() { + return appid; + } + + public String getMch_id() { + return mch_id; + } + + public String getDevice_info() { + return device_info; + } + + public String getNonce_str() { + return nonce_str; + } + + public String getSign() { + return sign; + } + + public String getResult_code() { + return result_code; + } + + public String getErr_code() { + return err_code; + } + + public String getErr_code_des() { + return err_code_des; + } + + public String getOpenid() { + return openid; + } + + public String getIs_subscribe() { + return is_subscribe; + } + + public String getTrade_type() { + return trade_type; + } + + public String getBank_type() { + return bank_type; + } + + public String getTotal_fee() { + return total_fee; + } + + public String getFee_type() { + return fee_type; + } + + public String getCash_fee() { + return cash_fee; + } + + public String getCash_fee_type() { + return cash_fee_type; + } + + public String getCoupon_fee() { + return coupon_fee; + } + + public String getCoupon_count() { + return coupon_count; + } + + public String getCoupon_batch_id_$n() { + return coupon_batch_id_$n; + } + + public String getCoupon_id_$n() { + return coupon_id_$n; + } + + public String getCoupon_fee_$n() { + return coupon_fee_$n; + } + + public String getTransaction_id() { + return transaction_id; + } - public String getOut_trade_no() { - return out_trade_no; - } + public String getOut_trade_no() { + return out_trade_no; + } - public String getAttach() { - return attach; - } + public String getAttach() { + return attach; + } - public String getTime_end() { - return time_end; - } + public String getTime_end() { + return time_end; + } - public void setReturn_code(String return_code) { - this.return_code = return_code; - } + public void setReturn_code(String return_code) { + this.return_code = return_code; + } - public void setReturn_msg(String return_msg) { - this.return_msg = return_msg; - } + public void setReturn_msg(String return_msg) { + this.return_msg = return_msg; + } - public void setAppid(String appid) { - this.appid = appid; - } + public void setAppid(String appid) { + this.appid = appid; + } - public void setMch_id(String mch_id) { - this.mch_id = mch_id; - } - - public void setDevice_info(String device_info) { - this.device_info = device_info; - } - - public void setNonce_str(String nonce_str) { - this.nonce_str = nonce_str; - } - - public void setSign(String sign) { - this.sign = sign; - } - - public void setResult_code(String result_code) { - this.result_code = result_code; - } - - public void setErr_code(String err_code) { - this.err_code = err_code; - } - - public void setErr_code_des(String err_code_des) { - this.err_code_des = err_code_des; - } - - public void setOpenid(String openid) { - this.openid = openid; - } - - public void setIs_subscribe(String is_subscribe) { - this.is_subscribe = is_subscribe; - } - - public void setTrade_type(String trade_type) { - this.trade_type = trade_type; - } - - public void setBank_type(String bank_type) { - this.bank_type = bank_type; - } - - public void setTotal_fee(String total_fee) { - this.total_fee = total_fee; - } - - public void setFee_type(String fee_type) { - this.fee_type = fee_type; - } - - public void setCash_fee(String cash_fee) { - this.cash_fee = cash_fee; - } - - public void setCash_fee_type(String cash_fee_type) { - this.cash_fee_type = cash_fee_type; - } - - public void setCoupon_fee(String coupon_fee) { - this.coupon_fee = coupon_fee; - } - - public void setCoupon_count(String coupon_count) { - this.coupon_count = coupon_count; - } - - public void setCoupon_batch_id_$n(String coupon_batch_id_$n) { - this.coupon_batch_id_$n = coupon_batch_id_$n; - } - - public void setCoupon_id_$n(String coupon_id_$n) { - this.coupon_id_$n = coupon_id_$n; - } - - public void setCoupon_fee_$n(String coupon_fee_$n) { - this.coupon_fee_$n = coupon_fee_$n; - } - - public void setTransaction_id(String transaction_id) { - this.transaction_id = transaction_id; - } - - public void setOut_trade_no(String out_trade_no) { - this.out_trade_no = out_trade_no; - } - - public void setAttach(String attach) { - this.attach = attach; - } - - public void setTime_end(String time_end) { - this.time_end = time_end; - } - - @Override - public String toString() { - return "WxMpPayCallback [return_code=" + return_code + ", return_msg=" + return_msg + ", appid=" + appid + ", mch_id=" + mch_id + ", device_info=" + device_info + ", nonce_str=" + nonce_str + ", sign=" + sign + ", result_code=" + result_code + ", err_code=" + err_code - + ", err_code_des=" + err_code_des + ", openid=" + openid + ", is_subscribe=" + is_subscribe + ", trade_type=" + trade_type + ", bank_type=" + bank_type + ", total_fee=" + total_fee + ", fee_type=" + fee_type + ", cash_fee=" + cash_fee + ", cash_fee_type=" - + cash_fee_type + ", coupon_fee=" + coupon_fee + ", coupon_count=" + coupon_count + ", coupon_batch_id_$n=" + coupon_batch_id_$n + ", coupon_id_$n=" + coupon_id_$n + ", coupon_fee_$n=" + coupon_fee_$n + ", transaction_id=" + transaction_id + ", out_trade_no=" - + out_trade_no + ", attach=" + attach + ", time_end=" + time_end + "]"; - } + public void setMch_id(String mch_id) { + this.mch_id = mch_id; + } + + public void setDevice_info(String device_info) { + this.device_info = device_info; + } + + public void setNonce_str(String nonce_str) { + this.nonce_str = nonce_str; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public void setResult_code(String result_code) { + this.result_code = result_code; + } + + public void setErr_code(String err_code) { + this.err_code = err_code; + } + + public void setErr_code_des(String err_code_des) { + this.err_code_des = err_code_des; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public void setIs_subscribe(String is_subscribe) { + this.is_subscribe = is_subscribe; + } + + public void setTrade_type(String trade_type) { + this.trade_type = trade_type; + } + + public void setBank_type(String bank_type) { + this.bank_type = bank_type; + } + + public void setTotal_fee(String total_fee) { + this.total_fee = total_fee; + } + + public void setFee_type(String fee_type) { + this.fee_type = fee_type; + } + + public void setCash_fee(String cash_fee) { + this.cash_fee = cash_fee; + } + + public void setCash_fee_type(String cash_fee_type) { + this.cash_fee_type = cash_fee_type; + } + + public void setCoupon_fee(String coupon_fee) { + this.coupon_fee = coupon_fee; + } + + public void setCoupon_count(String coupon_count) { + this.coupon_count = coupon_count; + } + + public void setCoupon_batch_id_$n(String coupon_batch_id_$n) { + this.coupon_batch_id_$n = coupon_batch_id_$n; + } + + public void setCoupon_id_$n(String coupon_id_$n) { + this.coupon_id_$n = coupon_id_$n; + } + + public void setCoupon_fee_$n(String coupon_fee_$n) { + this.coupon_fee_$n = coupon_fee_$n; + } + + public void setTransaction_id(String transaction_id) { + this.transaction_id = transaction_id; + } + + public void setOut_trade_no(String out_trade_no) { + this.out_trade_no = out_trade_no; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public void setTime_end(String time_end) { + this.time_end = time_end; + } + + @Override + public String toString() { + return "WxMpPayCallback [return_code=" + return_code + ", return_msg=" + + return_msg + ", appid=" + appid + ", mch_id=" + mch_id + + ", device_info=" + device_info + ", nonce_str=" + nonce_str + + ", sign=" + sign + ", result_code=" + result_code + + ", err_code=" + err_code + ", err_code_des=" + err_code_des + + ", openid=" + openid + ", is_subscribe=" + is_subscribe + + ", trade_type=" + trade_type + ", bank_type=" + bank_type + + ", total_fee=" + total_fee + ", fee_type=" + fee_type + + ", cash_fee=" + cash_fee + ", cash_fee_type=" + cash_fee_type + + ", coupon_fee=" + coupon_fee + ", coupon_count=" + + coupon_count + ", coupon_batch_id_$n=" + coupon_batch_id_$n + + ", coupon_id_$n=" + coupon_id_$n + ", coupon_fee_$n=" + + coupon_fee_$n + ", transaction_id=" + transaction_id + + ", out_trade_no=" + out_trade_no + ", attach=" + attach + + ", time_end=" + time_end + "]"; + } } From 5630b865c21a3d40ae31e136cf4e837359999746 Mon Sep 17 00:00:00 2001 From: Daniel Qian Date: Wed, 26 Aug 2015 08:42:00 +0800 Subject: [PATCH 17/19] issue #200 --- .../src/main/java/me/chanjar/weixin/cp/api/WxCpService.java | 2 +- .../src/main/java/me/chanjar/weixin/mp/api/WxMpService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index ac07ea6b..a87c3266 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -408,7 +408,7 @@ public interface WxCpService { *
* @param redirectUri * @param state - * @return code + * @return url */ String oauth2buildAuthorizationUrl(String redirectUri, String state); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 7b577d6c..5c15e89b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -526,7 +526,7 @@ public interface WxMpService { *
* @param scope * @param state - * @return code + * @return url */ public String oauth2buildAuthorizationUrl(String scope, String state); @@ -539,7 +539,7 @@ public interface WxMpService { * 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode * @param scope * @param state - * @return code + * @return url */ public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state); /** From a645a2826786fb70b98703a4200465d7d822c24f Mon Sep 17 00:00:00 2001 From: alanchen Date: Thu, 3 Sep 2015 17:54:51 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=9B=BE=E6=96=87=E6=B6=88=E6=81=AF=E8=B7=B3=E8=BD=AC=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/bean/WxMpMaterialNews.java | 19 +++++++++++++++++-- .../WxMpMaterialNewsArticleGsonAdapter.java | 7 +++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java index af64464d..f1de7d9e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java @@ -35,7 +35,8 @@ public class WxMpMaterialNews implements Serializable { * 4. contentSourceUrl 在图文消息页面点击“阅读原文”后的页面链接 * 5. content (必填) 图文消息页面的内容,支持HTML标签 * 6. digest 图文消息的描述 - * 7, showCoverPic 是否显示封面,true为显示,false为不显示 + * 7. showCoverPic 是否显示封面,true为显示,false为不显示 + * 8. url 点击图文消息跳转链接 *
* * @author chanjarster @@ -70,6 +71,12 @@ public class WxMpMaterialNews implements Serializable { */ private boolean showCoverPic; + /** + * 点击图文消息跳转链接 + * @return + */ + private String url; + public String getThumbMediaId() { return thumbMediaId; } @@ -126,11 +133,19 @@ public class WxMpMaterialNews implements Serializable { this.showCoverPic = showCoverPic; } + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + @Override public String toString() { return "WxMpMassNewsArticle [" + "thumbMediaId=" + thumbMediaId + ", author=" + author + ", title=" + title + ", contentSourceUrl=" + contentSourceUrl + ", content=" + content + ", digest=" + digest + - ", showCoverPic=" + showCoverPic + "]"; + ", showCoverPic=" + showCoverPic +", url=" + url + "]"; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java index 4f0e2e6d..141baeab 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java @@ -32,6 +32,9 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer Date: Fri, 11 Sep 2015 09:05:15 +0800 Subject: [PATCH 19/19] upgrade to 1.3.0 --- README.md | 6 ++++-- pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ebd57e6c..a519eaeb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ weixin-java-tools me.chanjar weixin-java-mp - 1.2.0 + 1.3.0 ``` @@ -27,7 +27,7 @@ weixin-java-tools me.chanjar weixin-java-cp - 1.2.0 + 1.3.0 ``` @@ -54,3 +54,5 @@ weixin-java-tools ## 关于Pull Request 非常欢迎和感谢对本项目发起Pull Request的同学,不过本项目基于[git flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支。 + +且本项目代码风格是用2个空格代表一个tab,因此在发起PR时注意一下,否则很容易发生在IDE格式化代码后与原代码产生大量diff,这样我在阅读PR的时候就很困难。 diff --git a/pom.xml b/pom.xml index a7ae7c05..40e2f2f2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 me.chanjar weixin-java-parent - 1.2.1-SNAPSHOT + 1.3.0 pom WeiXin Java Tools - Parent 微信公众号、企业号上级POM diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index f43efd03..a8d1da30 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ me.chanjar weixin-java-parent - 1.2.1-SNAPSHOT + 1.3.0 weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index e13e1664..d770a4c2 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -6,7 +6,7 @@ me.chanjar weixin-java-parent - 1.2.1-SNAPSHOT + 1.3.0 weixin-java-cp diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 1f4e7142..48999b06 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -6,7 +6,7 @@ me.chanjar weixin-java-parent - 1.2.1-SNAPSHOT + 1.3.0 weixin-java-mp WeiXin Java Tools - MP