Merge branch 'master' of https://github.com/foxinmy/weixin4j into wyying
This commit is contained in:
commit
a00c40d3bb
@ -21,6 +21,7 @@ import com.foxinmy.weixin4j.payment.mch.SettlementRecord;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
@ -48,6 +49,20 @@ public class CashApi extends MchApi {
|
||||
*
|
||||
* @param redpacket
|
||||
* 红包信息
|
||||
* @see #sendRedpack(Redpacket,String)
|
||||
*/
|
||||
public RedpacketSendResult sendRedpack(Redpacket redpacket)
|
||||
throws WeixinException {
|
||||
return sendRedpack(redpacket, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放红包 企业向微信用户个人发现金红包
|
||||
*
|
||||
* @param redpacket
|
||||
* 红包信息
|
||||
* @param appId
|
||||
* 应用ID 可为空 主要是针对企业号支付时传入的agentid
|
||||
* @return 发放结果
|
||||
* @see com.foxinmy.weixin4j.payment.mch.Redpacket
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RedpacketSendResult
|
||||
@ -59,10 +74,13 @@ public class CashApi extends MchApi {
|
||||
* 发放裂变红包接口</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public RedpacketSendResult sendRedpack(Redpacket redpacket)
|
||||
public RedpacketSendResult sendRedpack(Redpacket redpacket, String appId)
|
||||
throws WeixinException {
|
||||
super.declareMerchant(redpacket);
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(redpacket);
|
||||
if (StringUtil.isNotBlank(appId)) {
|
||||
obj.put("appid", appId);
|
||||
}
|
||||
obj.put("wxappid", obj.remove("appid"));
|
||||
obj.put("sign", weixinSignature.sign(obj));
|
||||
String param = XmlStream.map2xml(obj);
|
||||
|
||||
@ -38,12 +38,14 @@ import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.type.IdType;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
import com.foxinmy.weixin4j.type.TarType;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
import com.foxinmy.weixin4j.type.mch.BillType;
|
||||
import com.foxinmy.weixin4j.type.mch.RefundAccountType;
|
||||
import com.foxinmy.weixin4j.util.Consts;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.IOUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
@ -864,6 +866,8 @@ public class PayApi extends MchApi {
|
||||
* REFUND,返回当日退款订单
|
||||
* @param outputStream
|
||||
* 输出流
|
||||
* @param tarType
|
||||
* 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
|
||||
* @since V3
|
||||
* @see <a href=
|
||||
* "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">
|
||||
@ -871,7 +875,7 @@ public class PayApi extends MchApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void downloadBill(Date billDate, BillType billType,
|
||||
OutputStream outputStream) throws WeixinException {
|
||||
OutputStream outputStream, TarType tarType) throws WeixinException {
|
||||
if (billDate == null) {
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.add(Calendar.DAY_OF_MONTH, -1);
|
||||
@ -884,36 +888,47 @@ public class PayApi extends MchApi {
|
||||
Map<String, String> map = createBaseRequestMap(null);
|
||||
map.put("bill_date", formatBillDate);
|
||||
map.put("bill_type", billType.name());
|
||||
if (tarType != null) {
|
||||
map.put("tar_type", tarType.name());
|
||||
}
|
||||
map.put("sign", weixinSignature.sign(map));
|
||||
String param = XmlStream.map2xml(map);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
getRequestUri("downloadbill_uri"), param);
|
||||
|
||||
BufferedReader reader = null;
|
||||
BufferedWriter writer = null;
|
||||
try {
|
||||
writer = new BufferedWriter(new OutputStreamWriter(outputStream,
|
||||
Consts.UTF_8));
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
response.getBody(), Consts.UTF_8));
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException(e);
|
||||
} finally {
|
||||
if (TarType.GZIP == tarType) {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
IOUtil.copy(response.getBody(), outputStream);
|
||||
} catch (IOException e) {
|
||||
;
|
||||
}
|
||||
} else {
|
||||
BufferedReader reader = null;
|
||||
BufferedWriter writer = null;
|
||||
try {
|
||||
writer = new BufferedWriter(new OutputStreamWriter(
|
||||
outputStream, Consts.UTF_8));
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
response.getBody(), Consts.UTF_8));
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -58,6 +58,8 @@ public class MimeType implements Serializable {
|
||||
STREAM_MIMETYPES.add(valueOf("image/*"));
|
||||
STREAM_MIMETYPES.add(valueOf("audio/*"));
|
||||
STREAM_MIMETYPES.add(valueOf("video/*"));
|
||||
STREAM_MIMETYPES.add(valueOf("application/zip"));
|
||||
STREAM_MIMETYPES.add(valueOf("application/x-gzip"));
|
||||
}
|
||||
|
||||
public MimeType(String type) {
|
||||
|
||||
@ -73,11 +73,14 @@ public class WeixinResponse implements HttpResponse {
|
||||
return messageConverter.convert(clazz, response);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("IO error on convert to "
|
||||
+ typeReference, e);
|
||||
+ clazz, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("cannot convert to " + typeReference);
|
||||
if (clazz.isAssignableFrom(ApiResult.class)) {
|
||||
return (T) new ApiResult();
|
||||
}
|
||||
throw new RuntimeException("cannot convert to " + clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -29,8 +29,13 @@ public class MediaItem implements Serializable {
|
||||
/**
|
||||
* 媒体素材名称
|
||||
*/
|
||||
@JSONField(name = "filename")
|
||||
@JSONField(name = "name")
|
||||
private String name;
|
||||
/**
|
||||
* 图文页的URL,或者,当获取的列表是图片素材列表时,该字段是图片的URL
|
||||
*/
|
||||
@JSONField(name = "url")
|
||||
private String url;
|
||||
/**
|
||||
* 媒体素材最后更新时间
|
||||
*/
|
||||
@ -58,6 +63,14 @@ public class MediaItem implements Serializable {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
@ -81,7 +94,8 @@ public class MediaItem implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MediaItem [mediaId=" + mediaId + ", name=" + name
|
||||
+ ", updateTime=" + updateTime + ", articles=" + articles + "]";
|
||||
return "MediaItem [mediaId=" + mediaId + ", name=" + name + ",url="
|
||||
+ url + ", updateTime=" + updateTime + ", articles=" + articles
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ import com.foxinmy.weixin4j.sign.WeixinSignature;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.CustomsCity;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.type.TarType;
|
||||
import com.foxinmy.weixin4j.type.mch.BillType;
|
||||
import com.foxinmy.weixin4j.type.mch.RefundAccountType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
@ -511,6 +512,8 @@ public class WeixinPayProxy {
|
||||
* 下载对账单的类型 ALL,返回当日所有订单信息, 默认值 SUCCESS,返回当日成功支付的订单
|
||||
* REFUND,返回当日退款订单
|
||||
* @para outputStream 输出流
|
||||
* @param tarType
|
||||
* 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
|
||||
* @since V2 & V3
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see <a href=
|
||||
@ -519,8 +522,8 @@ public class WeixinPayProxy {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void downloadBill(Date billDate, BillType billType,
|
||||
OutputStream outputStream) throws WeixinException {
|
||||
payApi.downloadBill(billDate, billType, outputStream);
|
||||
OutputStream outputStream, TarType tarType) throws WeixinException {
|
||||
payApi.downloadBill(billDate, billType, outputStream, tarType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -676,6 +679,20 @@ public class WeixinPayProxy {
|
||||
*
|
||||
* @param redpacket
|
||||
* 红包信息
|
||||
* @see #sendRedpack(Redpacket,String)
|
||||
*/
|
||||
public RedpacketSendResult sendRedpack(Redpacket redpacket)
|
||||
throws WeixinException {
|
||||
return cashApi.sendRedpack(redpacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放红包 企业向微信用户个人发现金红包
|
||||
*
|
||||
* @param redpacket
|
||||
* 红包信息
|
||||
* @param appId
|
||||
* 应用ID 可为空 主要是针对企业号支付时传入的agentid
|
||||
* @return 发放结果
|
||||
* @see com.foxinmy.weixin4j.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.payment.mch.Redpacket
|
||||
@ -688,9 +705,9 @@ public class WeixinPayProxy {
|
||||
* 发放裂变红包接口</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public RedpacketSendResult sendRedpack(Redpacket redpacket)
|
||||
public RedpacketSendResult sendRedpack(Redpacket redpacket, String appId)
|
||||
throws WeixinException {
|
||||
return cashApi.sendRedpack(redpacket);
|
||||
return cashApi.sendRedpack(redpacket, appId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 压缩类型
|
||||
*
|
||||
* @className TarType
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年12月21日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public enum TarType {
|
||||
GZIP
|
||||
}
|
||||
@ -1559,7 +1559,7 @@ public class WeixinProxy {
|
||||
*
|
||||
* @param tplMessage
|
||||
* 模板消息主体
|
||||
* @return 发送结果
|
||||
* @return 发送的消息ID
|
||||
* @throws WeixinException
|
||||
* @see <a href=
|
||||
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">
|
||||
|
||||
@ -147,7 +147,7 @@ public class TmplApi extends MpApi {
|
||||
*
|
||||
* @param tplMessage
|
||||
* 消息对象
|
||||
* @return 发送结果
|
||||
* @return 发送的消息ID
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">模板消息</a>
|
||||
|
||||
@ -176,7 +176,7 @@ public class TemplateMessage implements Serializable {
|
||||
*
|
||||
* @param items
|
||||
*/
|
||||
public void pushItems(Map<String, NameValue> items) {
|
||||
public void setItems(Map<String, NameValue> items) {
|
||||
this.content = items;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
package com.foxinmy.weixin4j.mp.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.api.TmplApi;
|
||||
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
@ -39,7 +37,7 @@ public class TemplateTest extends TokenTest {
|
||||
TemplateMessage tplMessage = new TemplateMessage("touser",
|
||||
"template_id", "url");
|
||||
tplMessage.pushHead("head").pushTail("tail").pushItem("key1", "text1");
|
||||
ApiResult result = tmplApi.sendTmplMessage(tplMessage);
|
||||
Assert.assertEquals("0", result.getReturnCode());
|
||||
String result = tmplApi.sendTmplMessage(tplMessage);
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user