优化代码

This commit is contained in:
jy.hu 2014-11-05 11:09:30 +08:00
parent c4eb68ebcb
commit bbd12a8f2a
82 changed files with 683 additions and 688 deletions

View File

@ -43,15 +43,19 @@ weixin4j
+ **weixin-mp**: 分离为`weixin-mp-api``weixin-mp-server`两个工程
+ **weixin-mp**: 加入支付模块
* 2014-11-05
+ 优化了代码
接下来
------
* 退款&对账
* 企业号API封装
* 公众号退款接口
* 公众号智能接口
* 企业号API封装
* 微信消息加密
* 被扫支付

View File

@ -71,7 +71,7 @@ public class XmlResult implements Serializable {
}
public XmlResult() {
this("success", "");
this(SUCCESS.toLowerCase(), "");
}
public XmlResult(String returnCode, String returnMsg) {

View File

@ -0,0 +1,62 @@
package com.foxinmy.weixin4j.model;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 普通消息基类
* <p>
* <font color="red">回复图片等多媒体消息时需要预先上传多媒体文件到微信服务器,
* 假如服务器无法保证在五秒内处理并回复可以直接回复空串微信服务器不会对此作任何处理并且不会发起重试</font>
* </p>
*
* @className BaseMessage
* @author jy.hu
* @date 2014年4月6日
* @since JDK 1.7
*/
public class BaseMsg implements Serializable {
private static final long serialVersionUID = 7761192742840031607L;
@XStreamAlias("ToUserName")
private String toUserName; // 开发者微信号
@XStreamAlias("FromUserName")
private String fromUserName; // 发送方帐号一个OpenID
@XStreamAlias("CreateTime")
private long createTime = System.currentTimeMillis(); // 消息创建时间 整型
public BaseMsg() {
}
public BaseMsg(String toUserName, String fromUserName) {
this.toUserName = toUserName;
this.fromUserName = fromUserName;
}
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
}

View File

@ -1,8 +1,8 @@
package com.foxinmy.weixin4j.msg;
import java.io.Serializable;
import java.io.Writer;
import com.foxinmy.weixin4j.model.BaseMsg;
import com.foxinmy.weixin4j.type.MessageType;
import com.foxinmy.weixin4j.util.ClassUtil;
import com.foxinmy.weixin4j.xml.XStream;
@ -23,7 +23,7 @@ import com.thoughtworks.xstream.io.json.JsonWriter;
* @date 2014年4月6日
* @since JDK 1.7
*/
public class BaseMessage implements Serializable {
public class BaseMessage extends BaseMsg {
private static final long serialVersionUID = 7761192742840031607L;
private final static XStream xmlStream = XStream.get();
@ -34,12 +34,6 @@ public class BaseMessage implements Serializable {
}
});
@XStreamAlias("ToUserName")
private String toUserName; // 开发者微信号
@XStreamAlias("FromUserName")
private String fromUserName; // 发送方帐号一个OpenID
@XStreamAlias("CreateTime")
private long createTime = System.currentTimeMillis(); // 消息创建时间 整型
@XStreamAlias("MsgType")
private MessageType msgType; // 消息类型
@XStreamAlias("MsgId")
@ -68,33 +62,8 @@ public class BaseMessage implements Serializable {
public BaseMessage(MessageType msgType, String toUserName,
String fromUserName) {
super(toUserName, fromUserName);
this.msgType = msgType;
this.toUserName = toUserName;
this.fromUserName = fromUserName;
}
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public MessageType getMsgType() {

View File

@ -16,25 +16,25 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
public abstract class AbstractTokenHolder implements TokenHolder {
protected final String tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
protected final HttpRequest request = new HttpRequest();
private final String appid;
private final String appsecret;
private final WeixinConfig weixinConfig;
public AbstractTokenHolder() {
WeixinConfig weixinConfig = ConfigUtil.getWeixinConfig();
this.appid = weixinConfig.getAppId();
this.appsecret = weixinConfig.getAppSecret();
this.weixinConfig = ConfigUtil.getWeixinConfig();
}
public AbstractTokenHolder(String appid, String appsecret) {
this.appid = appid;
this.appsecret = appsecret;
this.weixinConfig = new WeixinConfig(appid, appsecret);
}
protected String getAppid() {
return this.appid;
return this.weixinConfig.getAppId();
}
protected String getAppsecret() {
return this.appsecret;
return this.weixinConfig.getAppSecret();
}
public WeixinConfig getConfig() {
return this.weixinConfig;
}
}

View File

@ -5,6 +5,7 @@ import org.apache.commons.lang3.StringUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisException;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
@ -74,7 +75,7 @@ public class RedisTokenHolder extends AbstractTokenHolder {
}
token.setTime(System.currentTimeMillis());
token.setOpenid(appid);
} catch (Exception e) {
} catch (JedisException e) {
jedisPool.returnBrokenResource(jedis);
} finally {
jedisPool.returnResource(jedis);

View File

@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.token;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.model.WeixinConfig;
/**
* 获取Token接口
@ -16,5 +17,7 @@ import com.foxinmy.weixin4j.model.Token;
* @see com.foxinmy.weixin4j.token.RedisTokenHolder
*/
public interface TokenHolder {
public WeixinConfig getConfig();
public Token getToken() throws WeixinException;
}

View File

@ -1,5 +1,6 @@
package com.foxinmy.weixin4j.util;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -13,9 +14,18 @@ import java.util.Date;
* @see
*/
public class DateUtil {
private static final String YYYYMMDD = "yyyyMMdd";
private static final String yyyyMMdd = "yyyyMMdd";
private static final String yyyyMMddHHmmss = "yyyyMMddHHmmss";
public static String fortmatYYYYMMDD(Date date) {
return new SimpleDateFormat(YYYYMMDD).format(date);
public static String fortmat2yyyyMMdd(Date date) {
return new SimpleDateFormat(yyyyMMdd).format(date);
}
public static String fortmat2yyyyMMddHHmmss(Date date) {
return new SimpleDateFormat(yyyyMMddHHmmss).format(date);
}
public static String format2fee(double fee) {
return new DecimalFormat("#").format(fee * 100);
}
}

View File

@ -23,8 +23,8 @@ public class Map2ObjectConverter extends MapConverter {
@Override
public Object unmarshal(HierarchicalStreamReader reader,
UnmarshallingContext context) {
Map<String,String> map = new HashMap<String, String>();
while(reader.hasMoreChildren()){
Map<String, String> map = new HashMap<String, String>();
while (reader.hasMoreChildren()) {
reader.moveDown();
map.put(reader.getNodeName(), reader.getValue());
reader.moveUp();
@ -37,12 +37,13 @@ public class Map2ObjectConverter extends MapConverter {
MarshallingContext context) {
Map<?, ?> map = (Map<?, ?>) source;
for (Entry<?, ?> entry : map.entrySet()) {
if (StringUtils.isBlank((String) entry.getValue())) {
String value = (String) entry.getValue();
if (StringUtils.isBlank(value)) {
continue;
}
ExtendedHierarchicalStreamWriterHelper.startNode(writer, entry
.getKey().toString(), entry.getClass());
writer.setValue(entry.getValue().toString());
writer.setValue(value);
writer.endNode();
}
}

View File

@ -27,16 +27,16 @@ import com.foxinmy.weixin4j.mp.model.Group;
import com.foxinmy.weixin4j.mp.model.MpArticle;
import com.foxinmy.weixin4j.mp.model.QRParameter;
import com.foxinmy.weixin4j.mp.model.User;
import com.foxinmy.weixin4j.mp.model.UserToken;
import com.foxinmy.weixin4j.mp.model.OauthToken;
import com.foxinmy.weixin4j.mp.msg.model.Article;
import com.foxinmy.weixin4j.mp.msg.model.BaseMsg;
import com.foxinmy.weixin4j.mp.msg.notify.BaseNotify;
import com.foxinmy.weixin4j.mp.payment.BillType;
import com.foxinmy.weixin4j.mp.payment.IdQuery;
import com.foxinmy.weixin4j.mp.payment.IdType;
import com.foxinmy.weixin4j.mp.payment.v2.Order;
import com.foxinmy.weixin4j.mp.payment.v3.Refund;
import com.foxinmy.weixin4j.mp.response.TemplateMessage;
import com.foxinmy.weixin4j.mp.type.BillType;
import com.foxinmy.weixin4j.mp.type.IdQuery;
import com.foxinmy.weixin4j.mp.type.IdType;
import com.foxinmy.weixin4j.token.FileTokenHolder;
import com.foxinmy.weixin4j.token.TokenHolder;
import com.foxinmy.weixin4j.type.MediaType;
@ -411,11 +411,11 @@ public class WeixinProxy {
* @throws WeixinException
* @see <a
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E7%BD%91%E9%A1%B5%E6%8E%88%E6%9D%83%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF#.E7.AC.AC.E4.BA.8C.E6.AD.A5.EF.BC.9A.E9.80.9A.E8.BF.87code.E6.8D.A2.E5.8F.96.E7.BD.91.E9.A1.B5.E6.8E.88.E6.9D.83access_token">获取用户token</a>
* @see com.foxinmy.weixin4j.mp.model.UserToken
* @see com.foxinmy.weixin4j.mp.model.OauthToken
* @see com.foxinmy.weixin4j.mp.api.UserApi
*/
public UserToken getAccessToken(String code) throws WeixinException {
return userApi.getAccessToken(code);
public OauthToken getOauthToken(String code) throws WeixinException {
return userApi.getOauthToken(code);
}
/**
@ -428,11 +428,11 @@ public class WeixinProxy {
* @see <a
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E7%BD%91%E9%A1%B5%E6%8E%88%E6%9D%83%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF#.E7.AC.AC.E5.9B.9B.E6.AD.A5.EF.BC.9A.E6.8B.89.E5.8F.96.E7.94.A8.E6.88.B7.E4.BF.A1.E6.81.AF.28.E9.9C.80scope.E4.B8.BA_snsapi_userinfo.29">拉取用户信息</a>
* @see com.foxinmy.weixin4j.mp.model.User
* @see com.foxinmy.weixin4j.mp.model.UserToken
* @see com.foxinmy.weixin4j.mp.model.OauthToken
* @see com.foxinmy.weixin4j.mp.api.UserApi
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#getAccessToken(String)}
*/
public User getUser(UserToken token) throws WeixinException {
public User getUser(OauthToken token) throws WeixinException {
return userApi.getUser(token);
}
@ -721,6 +721,8 @@ public class WeixinProxy {
*
* @param weixinAccount
* 商户信息
* @param openId
* 用户ID
* @param transid
* 交易单号
* @param orderNo
@ -733,11 +735,11 @@ public class WeixinProxy {
* @throws WeixinException
* @see com.foxinmy.weixin4j.mp.api.PayApi
*/
public JsonResult deliverNotify(WeixinAccount weixinAccount,
public JsonResult deliverNotify(WeixinAccount weixinAccount, String openId,
String transid, String orderNo, boolean status, String statusMsg)
throws WeixinException {
return payApi.deliverNotify(weixinAccount, transid, orderNo, status,
statusMsg);
return payApi.deliverNotify(weixinAccount, openId, transid, orderNo,
status, statusMsg);
}
/**
@ -862,7 +864,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.mp.api.PayApi
* @throws WeixinException
*/
public String getShorturl(WeixinAccount weixinAccount, String url)
public String getPayShorturl(WeixinAccount weixinAccount, String url)
throws WeixinException {
return payApi.getShorturl(weixinAccount, url);
}

View File

@ -28,13 +28,12 @@ import com.foxinmy.weixin4j.http.Response;
import com.foxinmy.weixin4j.http.XmlResult;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.model.WeixinAccount;
import com.foxinmy.weixin4j.mp.payment.BillType;
import com.foxinmy.weixin4j.mp.payment.IdQuery;
import com.foxinmy.weixin4j.mp.payment.IdType;
import com.foxinmy.weixin4j.mp.payment.PayUtil;
import com.foxinmy.weixin4j.mp.payment.RefundConverter;
import com.foxinmy.weixin4j.mp.payment.v2.Order;
import com.foxinmy.weixin4j.mp.payment.v3.Refund;
import com.foxinmy.weixin4j.mp.payment.v3.RefundConverter;
import com.foxinmy.weixin4j.mp.type.BillType;
import com.foxinmy.weixin4j.mp.type.IdQuery;
import com.foxinmy.weixin4j.mp.util.ExcelUtil;
import com.foxinmy.weixin4j.token.TokenHolder;
import com.foxinmy.weixin4j.util.ConfigUtil;
@ -62,6 +61,9 @@ public class PayApi extends BaseApi {
* 发货通知
*
* @param weixinAccount
* 商户信息
* @param openId
* 用户ID
* @param transid
* 交易单号
* @param orderNo
@ -73,7 +75,7 @@ public class PayApi extends BaseApi {
* @return
* @throws WeixinException
*/
public JsonResult deliverNotify(WeixinAccount weixinAccount,
public JsonResult deliverNotify(WeixinAccount weixinAccount, String openId,
String transid, String orderNo, boolean status, String statusMsg)
throws WeixinException {
String delivernotify_uri = getRequestUri("delivernotify_uri");
@ -83,7 +85,7 @@ public class PayApi extends BaseApi {
param.put("appid", weixinAccount.getAppId());
param.put("appkey", weixinAccount.getPaySignKey());
// 用户购买的openId
param.put("openid", weixinAccount.getOpenId());
param.put("openid", openId);
param.put("transid", transid);
param.put("out_trade_no", orderNo);
param.put("deliver_timestamp", System.currentTimeMillis() / 1000 + "");
@ -165,8 +167,7 @@ public class PayApi extends BaseApi {
*/
public JsonResult updateFeedback(String openId, String feedbackId)
throws WeixinException {
String payfeedback_update_uri = ConfigUtil
.getValue("payfeedback_update_uri");
String payfeedback_update_uri = getRequestUri("payfeedback_update_uri");
Token token = tokenHolder.getToken();
Response response = request.get(String.format(payfeedback_update_uri,
token.getAccessToken(), openId, feedbackId));
@ -288,7 +289,7 @@ public class PayApi extends BaseApi {
if (billType == null) {
billType = BillType.ALL;
}
String _billDate = DateUtil.fortmatYYYYMMDD(billDate);
String _billDate = DateUtil.fortmat2yyyyMMdd(billDate);
String bill_path = ConfigUtil.getValue("bill_path");
String fileName = String.format("%s_%s_%s.xls", _billDate, billType
.name().toLowerCase(), weixinAccount.getAppId());
@ -356,13 +357,4 @@ public class PayApi extends BaseApi {
Response response = request.post(refundquery_uri, param);
return new RefundConverter().fromXML(response.getAsString());
}
public static void main(String[] args) throws Exception {
WeixinAccount weixinAccount = new WeixinAccount("wx0d1d598c0c03c999",
null, "GATFzDwbQdbbci3QEQxX2rUBvwTrsMiZ", "10020674");
PayApi payApi = new PayApi(null);
System.out.println(payApi.refundQuery(weixinAccount, new IdQuery(
"T0002", IdType.ORDERNO)));
}
}

View File

@ -9,7 +9,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.Response;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.mp.model.QRParameter;
import com.foxinmy.weixin4j.mp.model.QRParameter.QRType;
import com.foxinmy.weixin4j.mp.type.QRType;
import com.foxinmy.weixin4j.token.TokenHolder;
/**
@ -64,11 +64,7 @@ public class QrApi extends BaseApi {
*/
public byte[] getQRData(int sceneId, int expireSeconds)
throws WeixinException {
QRParameter parameter = new QRParameter(sceneId, QRType.TEMPORARY,
expireSeconds);
if (expireSeconds <= 0) {
parameter.setQrType(QRType.PERMANENCE);
}
QRParameter parameter = new QRParameter(sceneId, expireSeconds);
return getQRData(parameter);
}

View File

@ -10,9 +10,10 @@ import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.JsonResult;
import com.foxinmy.weixin4j.http.Response;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.model.WeixinConfig;
import com.foxinmy.weixin4j.mp.model.Following;
import com.foxinmy.weixin4j.mp.model.OauthToken;
import com.foxinmy.weixin4j.mp.model.User;
import com.foxinmy.weixin4j.mp.model.UserToken;
import com.foxinmy.weixin4j.token.TokenHolder;
/**
@ -41,13 +42,15 @@ public class UserApi extends BaseApi {
* @throws WeixinException
* @see <a
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E7%BD%91%E9%A1%B5%E6%8E%88%E6%9D%83%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF#.E7.AC.AC.E4.BA.8C.E6.AD.A5.EF.BC.9A.E9.80.9A.E8.BF.87code.E6.8D.A2.E5.8F.96.E7.BD.91.E9.A1.B5.E6.8E.88.E6.9D.83access_token">获取用户token</a>
* @see com.foxinmy.weixin4j.mp.model.UserToken
* @see com.foxinmy.weixin4j.mp.model.OauthToken
*/
public UserToken getAccessToken(String code) throws WeixinException {
public OauthToken getOauthToken(String code) throws WeixinException {
String user_token_uri = getRequestUri("sns_user_token_uri");
Response response = request.get(String.format(user_token_uri, code));
WeixinConfig weixinConfig = tokenHolder.getConfig();
Response response = request.get(String.format(user_token_uri,
weixinConfig.getAppId(), weixinConfig.getAppSecret(), code));
return response.getAsObject(new TypeReference<UserToken>() {
return response.getAsObject(new TypeReference<OauthToken>() {
});
}
@ -61,10 +64,10 @@ public class UserApi extends BaseApi {
* @see <a
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E7%BD%91%E9%A1%B5%E6%8E%88%E6%9D%83%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF#.E7.AC.AC.E5.9B.9B.E6.AD.A5.EF.BC.9A.E6.8B.89.E5.8F.96.E7.94.A8.E6.88.B7.E4.BF.A1.E6.81.AF.28.E9.9C.80scope.E4.B8.BA_snsapi_userinfo.29">拉取用户信息</a>
* @see com.foxinmy.weixin4j.mp.model.User
* @see com.foxinmy.weixin4j.mp.model.UserToken
* {@link com.foxinmy.weixin4j.mp.api.UserApi#getAccessToken(String)}
* @see com.foxinmy.weixin4j.mp.model.OauthToken
* {@link com.foxinmy.weixin4j.mp.api.UserApi#getOauthToken(String)}
*/
public User getUser(UserToken token) throws WeixinException {
public User getUser(OauthToken token) throws WeixinException {
String user_info_uri = getRequestUri("sns_user_info_uri");
Response response = request.get(String.format(user_info_uri,
token.getAccessToken(), token.getOpenid()));

View File

@ -11,8 +11,8 @@ file_base_url=http://file.api.weixin.qq.com/cgi-bin
mch_base_url=https://api.mch.weixin.qq.com
# \u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u4fe1\u606f
user_auth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid={app_id}&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect
sns_user_token_uri=https://api.weixin.qq.com/sns/oauth2/access_token?appid={app_id}&secret={app_secret}&code=%s&grant_type=authorization_code
user_auth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect
sns_user_token_uri=https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code
sns_user_info_uri=https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN
# \u76f4\u63a5\u83b7\u53d6\u7528\u6237\u4fe1\u606f

View File

@ -46,14 +46,14 @@ public class AuthResult implements Serializable {
private AuthCode authCode;
private String location;
private UserToken accessToken;
private OauthToken accessToken;
public AuthResult(String location) {
this.location = location;
this.authCode = AuthCode.REDIRECT;
}
public AuthResult(UserToken accessToken) {
public AuthResult(OauthToken accessToken) {
this.authCode = AuthCode.OK;
this.accessToken = accessToken;
}
@ -79,11 +79,11 @@ public class AuthResult implements Serializable {
this.location = location;
}
public UserToken getAccessToken() {
public OauthToken getAccessToken() {
return accessToken;
}
public void setAccessToken(UserToken accessToken) {
public void setAccessToken(OauthToken accessToken) {
this.accessToken = accessToken;
}

View File

@ -35,14 +35,14 @@ public class Button implements Serializable {
public Button() {
}
public Button(String name) {
public Button(String name, String value, ButtonType buttonType) {
this.name = name;
}
public Button(String name, String url) {
this.name = name;
this.url = url;
this.type = ButtonType.view;
this.type = buttonType;
if (buttonType == ButtonType.click) {
this.key = value;
} else if (buttonType == ButtonType.view) {
this.url = value;
}
}
public String getName() {

View File

@ -78,7 +78,6 @@ public class CustomRecord implements Serializable {
public String getDesc() {
return desc;
}
}
@Override

View File

@ -82,5 +82,4 @@ public class Following implements Serializable {
sb.append(", nextOpenId=").append(nextOpenId).append("]");
return sb.toString();
}
}

View File

@ -26,49 +26,64 @@ public class MpArticle implements Serializable {
private String content;// 图文消息页面的内容支持HTML标签 非空
private String digest;// 图文消息的描述 可为空
@JSONField(name = "show_cover_pic")
private short showCoverPic; // 是否显示封面1为显示0为不显示 可为空
private String showCoverPic; // 是否显示封面1为显示0为不显示 可为空
public String getThumbMediaId() {
return thumbMediaId;
}
public void setThumbMediaId(String thumbMediaId) {
this.thumbMediaId = thumbMediaId;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public short getShowCoverPic() {
public String getShowCoverPic() {
return showCoverPic;
}
public void setShowCoverPic(short showCoverPic) {
this.showCoverPic = showCoverPic;
public void setShowCoverPic(boolean showCoverPic) {
this.showCoverPic = showCoverPic ? "1" : "0";
}
public MpArticle(String thumbMediaId, String title, String content) {
this.thumbMediaId = thumbMediaId;
this.title = title;
@ -78,6 +93,7 @@ public class MpArticle implements Serializable {
public MpArticle() {
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@ -4,16 +4,16 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.Token;
/**
* 用户token 一般通过授权页面获得
* 用户授权token 一般通过授权页面获得
*
* @className UserToken
* @className OauthToken
* @author jy.hu
* @date 2014年4月6日
* @since JDK 1.7
* @see com.foxinmy.weixin4j.mp.model.AuthResult
* @see com.foxinmy.weixin4j.mp.model.AuthResult.AuthScope
*/
public class UserToken extends Token {
public class OauthToken extends Token {
private static final long serialVersionUID = 1L;

View File

@ -2,8 +2,7 @@ package com.foxinmy.weixin4j.mp.model;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import com.foxinmy.weixin4j.mp.type.QRType;
/**
* 二维码参数对象
@ -16,6 +15,8 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
* @author jy.hu
* @date 2014年4月8日
* @since JDK 1.7
*
* @see com.foxinmy.weixin4j.mp.type.QRType
* @see <a
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E7%94%9F%E6%88%90%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%E4%BA%8C%E7%BB%B4%E7%A0%81">生成带参数的二维码</a>
*/
@ -23,26 +24,8 @@ public class QRParameter implements Serializable {
private static final long serialVersionUID = 6611187606558274253L;
public enum QRType {
TEMPORARY("QR_SCENE"), // 临时
PERMANENCE("QR_LIMIT_SCENE"); // 永久
private String name;
QRType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
@XStreamAlias("expire_seconds")
private int expireSeconds; // 该二维码有效时间以秒为单位 最大不超过1800
@XStreamAlias("action_name")
private QRType qrType; // 二维码类型QR_SCENE为临时,QR_LIMIT_SCENE为永久
@XStreamOmitField
@XStreamAlias("scene_id")
private int sceneId; // 场景值ID临时二维码时为32位非0整型永久二维码时最大值为100000目前参数只支持1--100000
public int getExpireSeconds() {
@ -69,20 +52,19 @@ public class QRParameter implements Serializable {
this.sceneId = sceneId;
}
public QRParameter(int expireSeconds, QRType qrType, int sceneId) {
public QRParameter(int sceneId, int expireSeconds) {
this(sceneId, expireSeconds, QRType.TEMPORARY);
if (expireSeconds <= 0) {
this.qrType = QRType.PERMANENCE;
}
}
public QRParameter(int sceneId, int expireSeconds, QRType qrType) {
this.expireSeconds = expireSeconds;
this.qrType = qrType;
this.sceneId = sceneId;
}
public QRParameter(QRType qrType, int sceneId) {
this(0, qrType, sceneId);
}
public QRParameter(int sceneId, int expireSeconds) {
this(0, null, sceneId);
}
public String toJson() {
/*
* XStream xstream = new XStream(new JsonHierarchicalStreamDriver() {
@ -94,17 +76,20 @@ public class QRParameter implements Serializable {
* "expire_seconds"); } return xstream.toXML(this);
*/
StringBuilder jsonBuilder = new StringBuilder("{");
jsonBuilder.append("\"action_name\":\"").append(qrType.getName()).append("\"");
jsonBuilder.append("\"action_name\":\"").append(qrType.getName())
.append("\"");
if (this.qrType == QRType.TEMPORARY) {
jsonBuilder.append(",\"expire_seconds\":").append(expireSeconds);
}
jsonBuilder.append(",\"action_info\":").append(String.format("{\"scene\": {\"scene_id\": %d}}", sceneId));
jsonBuilder.append(",\"action_info\":").append(
String.format("{\"scene\": {\"scene_id\": %d}}", sceneId));
jsonBuilder.append("}");
return jsonBuilder.toString();
}
@Override
public String toString() {
return "QRParameter [expireSeconds=" + expireSeconds + ", qrType=" + qrType + ", sceneId=" + sceneId + "]";
return "QRParameter [expireSeconds=" + expireSeconds + ", qrType="
+ qrType + ", sceneId=" + sceneId + "]";
}
}

View File

@ -4,6 +4,10 @@ import java.io.Serializable;
import org.apache.commons.lang3.StringUtils;
import com.foxinmy.weixin4j.mp.type.FaceSize;
import com.foxinmy.weixin4j.mp.type.Gender;
import com.foxinmy.weixin4j.mp.type.Lang;
/**
* 用户对象
* <p>
@ -33,48 +37,9 @@ public class User implements Serializable {
private Lang language; // 使用语言
private String unionid; // 只有在用户将公众号绑定到微信开放平台帐号后才会出现该字段
// 国家地区语言版本
public enum Lang {
zh_CN("简体"), zh_TW("繁体"), en("英语");
private String desc;
Lang(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
}
// 用户性别 值为1时是男性值为2时是女性值为0时是未知
public enum Gender {
male(1), female(2), unknown(0);
private int sex;
Gender(int sex) {
this.sex = sex;
}
public int getInt() {
return sex;
}
}
// 有0466496132数值可选0代表640*640正方形头像
public enum Size {
small(46), middle1(64), middle2(96), big(132);
private int size;
Size(int size) {
this.size = size;
}
public int getInt() {
return size;
}
public User() {
this.sex = 0;
this.language = Lang.zh_CN;
}
public String getOpenid() {
@ -139,8 +104,8 @@ public class User implements Serializable {
return headimgurl;
}
public String getHeadimgurl(Size size) {
if (StringUtils.isNoneBlank(headimgurl)) {
public String getHeadimgurl(FaceSize size) {
if (StringUtils.isNotBlank(headimgurl)) {
StringBuilder sb = new StringBuilder(headimgurl);
return sb.replace(0, (headimgurl.length() - 1), size.getInt() + "")
.toString();

View File

@ -1,7 +1,5 @@
package com.foxinmy.weixin4j.mp.payment;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
@ -13,55 +11,16 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @since JDK 1.7
* @see
*/
public class JsPayNotify implements Serializable {
public class JsPayNotify extends PayBaseInfo {
private static final long serialVersionUID = -4659030958445259803L;
@XStreamAlias("AppId")
private String appid; // 公众号ID
@XStreamAlias("TimeStamp")
private String timestamp; // 时间戳
@XStreamAlias("NonceStr")
private String noncestr; // 随机字符串
@XStreamAlias("OpenId")
private String openid; // 用户ID
@XStreamAlias("AppSignature")
private String appsignature; // 签名结果
@XStreamAlias("IsSubscribe")
private int issubscribe;
@XStreamAlias("SignMethod")
private String signmethod; // 签名方式
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getNoncestr() {
return noncestr;
}
public void setNoncestr(String noncestr) {
this.noncestr = noncestr;
}
public String getOpenid() {
return openid;
}
@ -70,14 +29,6 @@ public class JsPayNotify implements Serializable {
this.openid = openid;
}
public String getAppsignature() {
return appsignature;
}
public void setAppsignature(String appsignature) {
this.appsignature = appsignature;
}
public int getIssubscribe() {
return issubscribe;
}
@ -86,24 +37,12 @@ public class JsPayNotify implements Serializable {
this.issubscribe = issubscribe;
}
public String getSignmethod() {
return signmethod;
}
public void setSignmethod(String signmethod) {
this.signmethod = signmethod;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[JsPayNotify appid=").append(appid);
sb.append(", timestamp=").append(timestamp);
sb.append(", noncestr=").append(noncestr);
sb.append(", openid=").append(openid);
sb.append(", appsignature=").append(appsignature);
sb.append(", issubscribe=").append(issubscribe);
sb.append(", signmethod=").append(signmethod).append("]");
return sb.toString();
return "JsPayNotify [openid=" + openid + ", issubscribe=" + issubscribe
+ ", getAppId()=" + getAppId() + ", getTimeStamp()="
+ getTimeStamp() + ", getNonceStr()=" + getNonceStr()
+ ", getPaySign()=" + getPaySign() + ", getSignType()="
+ getSignType() + "]";
}
}

View File

@ -16,9 +16,11 @@ import com.foxinmy.weixin4j.mp.payment.v2.NativePayNotifyV2;
import com.foxinmy.weixin4j.mp.payment.v2.NativePayResponseV2;
import com.foxinmy.weixin4j.mp.payment.v2.PayFeedback;
import com.foxinmy.weixin4j.mp.payment.v2.PayPackageV2;
import com.foxinmy.weixin4j.mp.payment.v2.PayWarn;
import com.foxinmy.weixin4j.mp.payment.v3.NativePayNotifyV3;
import com.foxinmy.weixin4j.mp.payment.v3.NativePayResponseV3;
import com.foxinmy.weixin4j.mp.payment.v3.PayPackageV3;
import com.foxinmy.weixin4j.mp.type.TradeType;
import com.foxinmy.weixin4j.util.ConfigUtil;
import com.foxinmy.weixin4j.xml.XStream;
@ -47,8 +49,8 @@ public class PayAction {
// 此处的openid为微信用户的openid
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
weixinAccount.setOpenId("用户的openId");
payPackage = new PayPackageV3(weixinAccount, "商品描述", "系统内部订单号", 1d,
"IP地址", TradeType.JSAPI);
payPackage = new PayPackageV3(weixinAccount, "用户openid", "商品描述",
"系统内部订单号", 1d, "IP地址", TradeType.JSAPI);
// V2 支付
payPackage = new PayPackageV2("商品描述", weixinAccount.getPartnerId(),
"系统内部订单号", 1d, "回调地址", "IP地址");
@ -111,9 +113,9 @@ public class PayAction {
* &total_fee=1&trade_mode=1&trade_state=0&
* transaction_id=1221928801201410296039230054&transport_fee=0
*/
log.info("pay_notify_orderinfo,{}", objMap);
log.info("jspay_notify_orderinfo,{}", objMap);
JsPayNotify payNotify = XStream.get(inputStream, JsPayNotify.class);
log.info("pay_notify_userinfo,{}", payNotify);
log.info("jspay_notify_userinfo,{}", payNotify);
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
// 验证财付通签名
String sign = objMap.get("sign");
@ -126,9 +128,9 @@ public class PayAction {
}
objMap.clear();
// 验证微信签名
sign = payNotify.getAppsignature();
payNotify.setAppsignature(null);
payNotify.setSignmethod(null);
sign = payNotify.getPaySign();
payNotify.setPaySign(null);
payNotify.setSignType(null);
String vaild_sign = PayUtil.paysignSha(payNotify,
weixinAccount.getPaySignKey());
log.info("微信签名----->sign={},vaild_sign={}", sign, vaild_sign);
@ -153,7 +155,7 @@ public class PayAction {
public String jsNotifyV3(InputStream inputStream) {
com.foxinmy.weixin4j.mp.payment.v3.Order order = XStream.get(
inputStream, com.foxinmy.weixin4j.mp.payment.v3.Order.class);
log.info("order_info:", order);
log.info("jaapi_notify_order_info:", order);
String sign = order.getSign();
order.setSign(null);
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
@ -182,16 +184,16 @@ public class PayAction {
*
* @param inputStream
* xml数据
* @see com.foxinmy.weixin4j.mp.payment.PayWarn
* @see com.foxinmy.weixin4j.mp.payment.v2.PayWarn
* @return
*/
public String warning(InputStream inputStream) {
PayWarn payWarn = XStream.get(inputStream, PayWarn.class);
log.info("pay_warning,{}", payWarn);
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
String sign = payWarn.getAppsignature();
payWarn.setSignmethod(null);
payWarn.setAppsignature(null);
String sign = payWarn.getPaySign();
payWarn.setPaySign(null);
payWarn.setSignType(null);
// 验证微信签名
String vaild_sign = PayUtil.paysignSha(payWarn,
weixinAccount.getPaySignKey());
@ -224,9 +226,9 @@ public class PayAction {
NativePayNotifyV2.class);
log.info("native_pay_notify,{}", payNotify);
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
String sign = payNotify.getAppsignature();
payNotify.setAppsignature(null);
payNotify.setSignmethod(null);
String sign = payNotify.getPaySign();
payNotify.setPaySign(null);
payNotify.setSignType(null);
// 验证微信签名
String vaild_sign = PayUtil.paysignSha(payNotify,
weixinAccount.getPaySignKey());
@ -268,8 +270,8 @@ public class PayAction {
weixinAccount.getPaySignKey());
log.info("微信签名----->sign={},vaild_sign={}", sign, valid_sign);
// 生成Package
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, "商品描述",
"系统内部订单号", 1d, "IP地址", TradeType.NATIVE);
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, "用户openid",
"商品描述", "系统内部订单号", 1d, "IP地址", TradeType.NATIVE);
payPackage.setProduct_id(payNotify.getProductId());
if (!sign.equals(valid_sign)) {
NativePayResponseV3 payReponse = new NativePayResponseV3(
@ -303,8 +305,7 @@ public class PayAction {
obj.put("appid", feedback.getAppId());
obj.put("timestamp", feedback.getTimeStamp());
String sign = PayUtil.paysignSha(obj, weixinAccount.getPaySignKey());
log.info("微信签名----->sign={},vaild_sign={}", sign,
feedback.getAppSignature());
log.info("微信签名----->sign={},vaild_sign={}", sign, feedback.getPaySign());
return "success";
}

View File

@ -0,0 +1,94 @@
package com.foxinmy.weixin4j.mp.payment;
import java.io.Serializable;
import com.foxinmy.weixin4j.mp.type.SignType;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 基本信息
*
* @className PayBaseInfo
* @author jy
* @date 2014年11月5日
* @since JDK 1.7
* @see
*/
public class PayBaseInfo implements Serializable {
private static final long serialVersionUID = 1843024880782466990L;
@XStreamAlias("AppId")
private String appId; // 公众号ID
@XStreamAlias("TimeStamp")
private String timeStamp; // 时间戳
@XStreamAlias("NonceStr")
private String nonceStr; // 随机字符串
@XStreamAlias("AppSignature")
private String paySign; // 签名结果
@XStreamAlias("SignMethod")
private String signType; // 签名方式
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
public String getPaySign() {
return paySign;
}
public void setPaySign(String paySign) {
this.paySign = paySign;
}
public String getSignType() {
return signType;
}
public void setSignType(SignType signType) {
if (signType != null) {
this.signType = signType.name();
} else {
this.signType = null;
}
}
public PayBaseInfo() {
}
public PayBaseInfo(String appId, String timestamp, String noncestr) {
this.appId = appId;
this.timeStamp = timestamp;
this.nonceStr = noncestr;
}
@Override
public String toString() {
return "PayBaseInfo [appId=" + appId + ", timeStamp=" + timeStamp
+ ", nonceStr=" + nonceStr + ", paySign=" + paySign
+ ", signType=" + signType + "]";
}
}

View File

@ -1,18 +1,14 @@
package com.foxinmy.weixin4j.mp.payment;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.foxinmy.weixin4j.util.DateUtil;
public class PayPackage implements Serializable {
private static final long serialVersionUID = 3450161267802545790L;
protected static final NumberFormat FEE_FORMAT = new DecimalFormat("#");
protected static final DateFormat DATE_FORMAT = new SimpleDateFormat(
"yyyyMMddHHmmss");
private String body; // 商品描述 必须
private String attach; // 附加数据,原样返回 非必须
private String out_trade_no; // 商户系统内部的订单号 ,32 个字符内 可包含字母 ,确保 在商户系统唯一 必须
@ -26,39 +22,51 @@ public class PayPackage implements Serializable {
// beijing该时间取 自商户服务商品标记 非必须
private String goods_tag; // 商品标记,该字段不能随便 ,不使用请填空 非必须
private String notify_url; // 通知地址接收微信支付成功通知 必须
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getAttach() {
return attach;
}
public void setAttach(String attach) {
this.attach = attach;
}
public String getOut_trade_no() {
return out_trade_no;
}
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public String getTotal_fee() {
return total_fee;
}
public void setTotal_fee(double total_fee) {
this.total_fee = FEE_FORMAT.format(total_fee);
this.total_fee = DateUtil.format2fee(total_fee);
}
public String getSpbill_create_ip() {
return spbill_create_ip;
}
public void setSpbill_create_ip(String spbill_create_ip) {
this.spbill_create_ip = spbill_create_ip;
}
public String getTime_start() {
return time_start;
}
public void setTime_start(String time_start) {
this.time_start = time_start;
}
@ -68,44 +76,52 @@ public class PayPackage implements Serializable {
}
public void setTime_start(Date time_start) {
this.time_start = time_start != null
? DATE_FORMAT.format(time_start)
: null;;
this.time_start = time_start != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_start) : null;
;
}
public String getTime_expire() {
return time_expire;
}
public void setTime_expire(Date time_expire) {
this.time_expire = time_expire != null ? DATE_FORMAT
.format(time_expire) : null;;
this.time_expire = time_expire != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_expire) : null;
;
}
public String getGoods_tag() {
return goods_tag;
}
public void setGoods_tag(String goods_tag) {
this.goods_tag = goods_tag;
}
public String getNotify_url() {
return notify_url;
}
public void setNotify_url(String notify_url) {
this.notify_url = notify_url;
}
public PayPackage() {
}
public PayPackage(String body, String attach, String out_trade_no,
double total_fee, String spbill_create_ip, Date time_start,
Date time_expire, String goods_tag, String notify_url) {
this.body = body;
this.attach = attach;
this.out_trade_no = out_trade_no;
this.total_fee = FEE_FORMAT.format(total_fee * 100);
this.total_fee = DateUtil.format2fee(total_fee);
this.spbill_create_ip = spbill_create_ip;
this.time_start = time_start != null
? DATE_FORMAT.format(time_start)
: null;
this.time_expire = time_expire != null ? DATE_FORMAT
.format(time_expire) : null;
this.time_start = time_start != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_start) : null;
this.time_expire = time_expire != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_expire) : null;
this.goods_tag = goods_tag;
this.notify_url = notify_url;
}

View File

@ -1,74 +1,28 @@
package com.foxinmy.weixin4j.mp.payment;
import java.io.Serializable;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.util.RandomUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
public class PayRequest implements Serializable {
public class PayRequest extends PayBaseInfo {
private static final long serialVersionUID = -453746488398523883L;
// 公众号ID
@XStreamAlias("AppId")
private String appId;
// 当前时间戳
@XStreamAlias("TimeStamp")
private String timeStamp;
// 随机字符串
@XStreamAlias("NonceStr")
private String nonceStr;
// 订单详情扩展 订单信息组成该字符串
@XStreamAlias("Package")
@JSONField(name = "package")
private String packageInfo;
// 签名方式 数取值"SHA1"
@XStreamAlias("SignMethod")
private String signType;
// 商户将接口列表中的参数按照指定方式进行 签名,签名方式使用 signType中标示的签名方式,
@XStreamAlias("Appsignature")
private String paySign;
public PayRequest() {
this.timeStamp = System.currentTimeMillis() / 1000 + "";
this.nonceStr = RandomUtil.generateString(16);
this(null, null);
}
public PayRequest(String appId, String packageInfo, SignType signType,
String paySign) {
this.appId = appId;
this.timeStamp = System.currentTimeMillis() / 1000 + "";
this.nonceStr = RandomUtil.generateString(16);
public PayRequest(String appId, String packageInfo) {
super(appId, System.currentTimeMillis() / 1000 + "", RandomUtil
.generateString(16));
this.packageInfo = packageInfo;
this.signType = signType.name();
this.paySign = paySign;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
@JSONField(name = "package")
public String getPackageInfo() {
return packageInfo;
}
@ -76,20 +30,4 @@ public class PayRequest implements Serializable {
public void setPackageInfo(String packageInfo) {
this.packageInfo = packageInfo;
}
public String getSignType() {
return signType;
}
public void setSignType(SignType signType) {
this.signType = signType.name();
}
public String getPaySign() {
return paySign;
}
public void setPaySign(String paySign) {
this.paySign = paySign;
}
}

View File

@ -23,9 +23,11 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
import com.foxinmy.weixin4j.mp.payment.v2.JsPayRequestV2;
import com.foxinmy.weixin4j.mp.payment.v2.NativePayResponseV2;
import com.foxinmy.weixin4j.mp.payment.v2.PayPackageV2;
import com.foxinmy.weixin4j.mp.payment.v3.PayRequestV3;
import com.foxinmy.weixin4j.mp.payment.v3.PayPackageV3;
import com.foxinmy.weixin4j.mp.payment.v3.PayRequestV3;
import com.foxinmy.weixin4j.mp.payment.v3.PrePay;
import com.foxinmy.weixin4j.mp.type.SignType;
import com.foxinmy.weixin4j.mp.type.TradeType;
import com.foxinmy.weixin4j.util.MapUtil;
import com.foxinmy.weixin4j.util.RandomUtil;
import com.foxinmy.weixin4j.xml.XStream;
@ -153,6 +155,8 @@ public class PayUtil {
/**
* 生成V3.x版本JSAPI支付字符串
*
* @param openId
* 用户ID
* @param body
* 订单描述
* @param orderNo
@ -162,15 +166,15 @@ public class PayUtil {
* @param ip
* @param notifyUrl
* 支付通知地址
* @param weixinConfig
* appid等信息
* @return
* @param weixinAccount
* 商户信息
* @return 支付json串
* @throws PayException
*/
public static String createPayJsRequestJsonV3(String body, String orderNo,
double orderFee, String ip, String notifyUrl,
public static String createPayJsRequestJsonV3(String openId, String body,
String orderNo, double orderFee, String ip, String notifyUrl,
WeixinAccount weixinAccount) throws PayException {
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, body,
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, openId, body,
orderNo, orderFee, ip, TradeType.JSAPI);
payPackage.setNotify_url(notifyUrl);
return createPayJsRequestJsonV3(payPackage, weixinAccount);
@ -352,8 +356,9 @@ public class PayUtil {
"2270e6c67cf4ff48fe2c6d7cc5a42157",
"6b506ef5fefba3142653a9affd2648d8", "10020674",
"oyFLst1bqtuTcxK-ojF8hOGtLQao");
System.out.println(PayUtil.createPayJsRequestJsonV3("测试", "T001",
1d, "192.0.0.1", "http://182.92.74.85:8082/pay/notify",
System.out.println(PayUtil.createPayJsRequestJsonV3(
"oyFLst1bqtuTcxK-ojF8hOGtLQao", "测试", "T001", 1d,
"192.0.0.1", "http://182.92.74.85:8082/pay/notify",
weixinAccount));
} catch (PayException e) {
e.printStackTrace();

View File

@ -1,96 +0,0 @@
package com.foxinmy.weixin4j.mp.payment;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("xml")
public class PayWarn implements Serializable {
private static final long serialVersionUID = 2334592957844332640L;
@XStreamAlias("AppId")
private String appid;
@XStreamAlias("ErrorType")
private String errortype;
@XStreamAlias("Description")
private String description;
@XStreamAlias("AlarmContent")
private String alarmcontent;
@XStreamAlias("TimeStamp")
private String timestamp;
@XStreamAlias("AppSignature")
private String appsignature;
@XStreamAlias("SignMethod")
private String signmethod;
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getErrortype() {
return errortype;
}
public void setErrortype(String errortype) {
this.errortype = errortype;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAlarmcontent() {
return alarmcontent;
}
public void setAlarmcontent(String alarmcontent) {
this.alarmcontent = alarmcontent;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getAppsignature() {
return appsignature;
}
public void setAppsignature(String appsignature) {
this.appsignature = appsignature;
}
public String getSignmethod() {
return signmethod;
}
public void setSignmethod(String signmethod) {
this.signmethod = signmethod;
}
@Override
public String toString() {
return "PayWarn [appid=" + appid + ", errortype=" + errortype
+ ", description=" + description + ", alarmcontent="
+ alarmcontent + ", timestamp=" + timestamp + ", appsignature="
+ appsignature + ", signmethod=" + signmethod + "]";
}
}

View File

@ -1,5 +0,0 @@
package com.foxinmy.weixin4j.mp.payment;
public enum SignType {
SHA1,MD5
}

View File

@ -1,5 +1,7 @@
package com.foxinmy.weixin4j.mp.payment.v2;
import java.beans.Transient;
import org.apache.commons.codec.digest.DigestUtils;
import com.alibaba.fastjson.annotation.JSONField;
@ -32,6 +34,7 @@ public class JsPayRequestV2 extends PayRequest {
weixinAccount.getPartnerKey()));
}
@Transient
@JSONField(serialize = false)
private String package2string(PayPackageV2 payPackage, String partnerKey) {
StringBuilder sb = new StringBuilder();
@ -56,9 +59,10 @@ public class JsPayRequestV2 extends PayRequest {
@Override
public String toString() {
return "JsPayRequest [getAppId()=" + getAppId() + ", getTimeStamp()="
return "JsPayRequestV2 [getPackageInfo()=" + getPackageInfo()
+ ", getAppId()=" + getAppId() + ", getTimeStamp()="
+ getTimeStamp() + ", getNonceStr()=" + getNonceStr()
+ ", getPackageInfo()=" + getPackageInfo() + ", getSignType()="
+ getSignType() + ", getPaySign()=" + getPaySign() + "]";
+ ", getPaySign()=" + getPaySign() + ", getSignType()="
+ getSignType() + "]";
}
}
}

View File

@ -28,11 +28,11 @@ public class NativePayNotifyV2 extends JsPayNotify {
@Override
public String toString() {
return "PayNativeNotifyV2 [productId=" + productId + ", getAppid()="
+ getAppid() + ", getTimestamp()=" + getTimestamp()
+ ", getNoncestr()=" + getNoncestr() + ", getOpenid()="
+ getOpenid() + ", getAppsignature()=" + getAppsignature()
+ ", getIssubscribe()=" + getIssubscribe()
+ ", getSignmethod()=" + getSignmethod() + "]";
return "NativePayNotifyV2 [productId=" + productId + ", getOpenid()="
+ getOpenid() + ", getIssubscribe()=" + getIssubscribe()
+ ", getAppId()=" + getAppId() + ", getTimeStamp()="
+ getTimeStamp() + ", getNonceStr()=" + getNonceStr()
+ ", getPaySign()=" + getPaySign() + ", getSignType()="
+ getSignType() + "]";
}
}
}

View File

@ -4,7 +4,7 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* Native支付响应
* Native支付时的回调响应
*
* @className NativePayResponseV2
* @author jy
@ -47,9 +47,9 @@ public class NativePayResponseV2 extends JsPayRequestV2 {
@Override
public String toString() {
return "NativePayResponseV2 [retCode=" + retCode + ", retMsg=" + retMsg
+ ", getAppId()=" + getAppId() + ", getTimeStamp()="
+ getTimeStamp() + ", getNonceStr()=" + getNonceStr()
+ ", getPackageInfo()=" + getPackageInfo() + ", getSignType()="
+ getSignType() + ", getPaySign()=" + getPaySign() + "]";
+ ", getPackageInfo()=" + getPackageInfo() + ", getAppId()="
+ getAppId() + ", getTimeStamp()=" + getTimeStamp()
+ ", getNonceStr()=" + getNonceStr() + ", getPaySign()="
+ getPaySign() + ", getSignType()=" + getSignType() + "]";
}
}

View File

@ -1,7 +1,6 @@
package com.foxinmy.weixin4j.mp.payment.v2;
import java.io.Serializable;
import com.foxinmy.weixin4j.mp.payment.PayBaseInfo;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
@ -14,7 +13,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
* @see
*/
@XStreamAlias("xml")
public class PayFeedback implements Serializable {
public class PayFeedback extends PayBaseInfo {
private static final long serialVersionUID = 7230049346213966310L;
@ -34,12 +33,6 @@ public class PayFeedback implements Serializable {
private String picInfo;
@XStreamAlias("MsgType")
private String status;
@XStreamAlias("AppId")
private String appId;
@XStreamAlias("TimeStamp")
private String timeStamp;
@XStreamAlias("AppSignature")
private String appSignature;
public String getFeedbackId() {
return feedbackId;
@ -105,36 +98,14 @@ public class PayFeedback implements Serializable {
this.status = status;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getAppSignature() {
return appSignature;
}
public void setAppSignature(String appSignature) {
this.appSignature = appSignature;
}
@Override
public String toString() {
return "PayFeedback [feedbackId=" + feedbackId + ", openId=" + openId
+ ", transId=" + transId + ", reason=" + reason + ", solution="
+ solution + ", extInfo=" + extInfo + ", picInfo=" + picInfo
+ ", status=" + status + ", appId=" + appId + ", timeStamp="
+ timeStamp + ", appSignature=" + appSignature + "]";
+ ", status=" + status + ", getAppId()=" + getAppId()
+ ", getTimeStamp()=" + getTimeStamp() + ", getNonceStr()="
+ getNonceStr() + ", getPaySign()=" + getPaySign()
+ ", getSignType()=" + getSignType() + "]";
}
}
}

View File

@ -5,9 +5,10 @@ import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import com.foxinmy.weixin4j.mp.payment.PayPackage;
import com.foxinmy.weixin4j.util.DateUtil;
/**
* 微信支付的订单详情
* V2支付的订单详情
*
* @className PayPackageV2
* @author jy
@ -33,26 +34,31 @@ public class PayPackageV2 extends PayPackage {
private String product_fee;
// 传入参数字符编码 取值范围:"GBK""UTF-8",默认:"GBK" 可为空
private String input_charset;
private String goods_tag;// 􏱙􏴱􏲹􏺯􏱮􏺰􏺱􏺲􏱫􏱥􏵧􏲛􏳙􏱙􏴱􏲹􏺯􏱮􏺰􏺱􏺲􏱫􏱥􏵧􏲛􏳙􏱙􏴱􏲹􏺯􏱮􏺰􏺱􏺲􏱫􏱥􏵧􏲛􏳙􏱙􏴱􏲹􏺯􏱮􏺰􏺱􏺲􏱫􏱥􏵧􏲛􏳙􏱙􏴱􏲹􏺯􏱮􏺰􏺱􏺲􏱫􏱥􏵧􏲛􏳙商品标记优惠券可能用到
// 可为空
public String getBank_type() {
return bank_type;
}
public void setBank_type(String bank_type) {
this.bank_type = bank_type;
}
public void setBody(String body) {
super.setBody(StringUtils.isBlank(body) ? "服务费用" : body);
}
public String getPartner() {
return partner;
}
public void setPartner(String partner) {
this.partner = partner;
}
public String getFee_type() {
return fee_type;
}
public void setFee_type(String fee_type) {
this.fee_type = fee_type;
}
@ -64,24 +70,23 @@ public class PayPackageV2 extends PayPackage {
public String getTransport_fee() {
return transport_fee;
}
public void setTransport_fee(double transport_fee) {
this.transport_fee = FEE_FORMAT.format(transport_fee);
this.transport_fee = DateUtil.format2fee(transport_fee);
}
public String getProduct_fee() {
return product_fee;
}
public void setProduct_fee(double product_fee) {
this.product_fee = FEE_FORMAT.format(product_fee);
}
public String getGoods_tag() {
return goods_tag;
}
public void setGoods_tag(String goods_tag) {
this.goods_tag = goods_tag;
this.product_fee = DateUtil.format2fee(product_fee);
}
public String getInput_charset() {
return input_charset;
}
public void setInput_charset(String input_charset) {
this.input_charset = input_charset;
}
@ -97,11 +102,13 @@ public class PayPackageV2 extends PayPackage {
this(null, null, null, out_trade_no, total_fee, null, spbill_create_ip,
null, null, 0d, 0d, null);
}
public PayPackageV2(String body, String out_trade_no, double total_fee,
String spbill_create_ip) {
this(body, null, null, out_trade_no, total_fee, null, spbill_create_ip,
null, null, 0d, 0d, null);
}
public PayPackageV2(String body, String partner, String out_trade_no,
double total_fee, String notify_url, String spbill_create_ip) {
this(body, null, partner, out_trade_no, total_fee, notify_url,
@ -117,10 +124,10 @@ public class PayPackageV2 extends PayPackage {
this.bank_type = "WX";
this.fee_type = "1";
this.input_charset = "UTF-8";
this.transport_fee = transport_fee > 0d ? FEE_FORMAT
.format(transport_fee * 100) : null;
this.product_fee = product_fee > 0 ? FEE_FORMAT
.format(product_fee * 100) : null;
this.transport_fee = transport_fee > 0d ? DateUtil
.format2fee(transport_fee) : null;
this.product_fee = product_fee > 0 ? DateUtil.format2fee(product_fee)
: null;
}
@Override
@ -128,7 +135,7 @@ public class PayPackageV2 extends PayPackage {
return "PayPackageV2 [bank_type=" + bank_type + ", partner=" + partner
+ ", fee_type=" + fee_type + ", transport_fee=" + transport_fee
+ ", product_fee=" + product_fee + ", input_charset="
+ input_charset + ", goods_tag=" + goods_tag
+ input_charset + ", goods_tag=" + getGoods_tag()
+ ", getBank_type()=" + getBank_type() + ", getPartner()="
+ getPartner() + ", getFee_type()=" + getFee_type()
+ ", getTransport_fee()=" + getTransport_fee()

View File

@ -0,0 +1,53 @@
package com.foxinmy.weixin4j.mp.payment.v2;
import com.foxinmy.weixin4j.mp.payment.PayBaseInfo;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("xml")
public class PayWarn extends PayBaseInfo {
private static final long serialVersionUID = 2334592957844332640L;
@XStreamAlias("ErrorType")
private String errortype;
@XStreamAlias("Description")
private String description;
@XStreamAlias("AlarmContent")
private String alarmcontent;
public String getErrortype() {
return errortype;
}
public void setErrortype(String errortype) {
this.errortype = errortype;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAlarmcontent() {
return alarmcontent;
}
public void setAlarmcontent(String alarmcontent) {
this.alarmcontent = alarmcontent;
}
@Override
public String toString() {
return "PayWarn [errortype=" + errortype + ", description="
+ description + ", alarmcontent=" + alarmcontent
+ ", getAppId()=" + getAppId() + ", getTimeStamp()="
+ getTimeStamp() + ", getNonceStr()=" + getNonceStr()
+ ", getPaySign()=" + getPaySign() + ", getSignType()="
+ getSignType() + "]";
}
}

View File

@ -4,7 +4,7 @@ import com.foxinmy.weixin4j.mp.payment.ApiResult;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* V3 Native支付回调时POST的信息
* Native支付回调时POST的信息
*
* @className PayNativeNotifyV3
* @author jy
@ -17,8 +17,6 @@ public class NativePayNotifyV3 extends ApiResult {
private static final long serialVersionUID = 4515471400239795492L;
@XStreamAlias("mch_id")
private String mchId;
@XStreamAlias("product_id")
private String productId;
@ -30,23 +28,14 @@ public class NativePayNotifyV3 extends ApiResult {
this.productId = productId;
}
public String getMchId() {
return mchId;
}
public void setMchId(String mchId) {
this.mchId = mchId;
}
@Override
public String toString() {
return "NativePayNotifyV3 [mchId=" + mchId + ", productId=" + productId
+ ", getAppId()=" + getAppId() + ", getNonceStr()="
return "NativePayNotifyV3 [mchId=" + getMchId() + ", productId="
+ productId + ", getAppId()=" + getAppId() + ", getNonceStr()="
+ getNonceStr() + ", getSign()=" + getSign()
+ ", getDeviceInfo()=" + getDeviceInfo() + ", toString()="
+ super.toString() + ", getReturnCode()=" + getReturnCode()
+ ", getReturnMsg()=" + getReturnMsg() + ", getResultCode()="
+ getResultCode() + ", getErrCode()=" + getErrCode()
+ ", getErrCodeDes()=" + getErrCodeDes() + "]";
+ ", getDeviceInfo()=" + getDeviceInfo() + ", getReturnCode()="
+ getReturnCode() + ", getReturnMsg()=" + getReturnMsg()
+ ", getResultCode()=" + getResultCode() + ", getErrCode()="
+ getErrCode() + ", getErrCodeDes()=" + getErrCodeDes() + "]";
}
}

View File

@ -9,7 +9,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* Native支付响应
* Native支付时的回调响应
*
* @className NativePayResponseV3
* @author jy
@ -50,9 +50,9 @@ public class NativePayResponseV3 extends ApiResult {
+ getAppId() + ", getMchId()=" + getMchId()
+ ", getNonceStr()=" + getNonceStr() + ", getSign()="
+ getSign() + ", getDeviceInfo()=" + getDeviceInfo()
+ ", toString()=" + super.toString() + ", getReturnCode()="
+ getReturnCode() + ", getReturnMsg()=" + getReturnMsg()
+ ", getResultCode()=" + getResultCode() + ", getErrCode()="
+ getErrCode() + ", getErrCodeDes()=" + getErrCodeDes() + "]";
+ ", getReturnCode()=" + getReturnCode() + ", getReturnMsg()="
+ getReturnMsg() + ", getResultCode()=" + getResultCode()
+ ", getErrCode()=" + getErrCode() + ", getErrCodeDes()="
+ getErrCodeDes() + "]";
}
}

View File

@ -1,9 +1,9 @@
package com.foxinmy.weixin4j.mp.payment.v3;
import com.foxinmy.weixin4j.mp.payment.ApiResult;
import com.foxinmy.weixin4j.mp.payment.CurrencyType;
import com.foxinmy.weixin4j.mp.payment.TradeState;
import com.foxinmy.weixin4j.mp.payment.TradeType;
import com.foxinmy.weixin4j.mp.type.CurrencyType;
import com.foxinmy.weixin4j.mp.type.TradeState;
import com.foxinmy.weixin4j.mp.type.TradeType;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
@ -164,9 +164,9 @@ public class Order extends ApiResult {
+ ", getAppId()=" + getAppId() + ", getMchId()=" + getMchId()
+ ", getNonceStr()=" + getNonceStr() + ", getSign()="
+ getSign() + ", getDeviceInfo()=" + getDeviceInfo()
+ ", toString()=" + super.toString() + ", getReturnCode()="
+ getReturnCode() + ", getReturnMsg()=" + getReturnMsg()
+ ", getResultCode()=" + getResultCode() + ", getErrCode()="
+ getErrCode() + ", getErrCodeDes()=" + getErrCodeDes() + "]";
+ ", getReturnCode()=" + getReturnCode() + ", getReturnMsg()="
+ getReturnMsg() + ", getResultCode()=" + getResultCode()
+ ", getErrCode()=" + getErrCode() + ", getErrCodeDes()="
+ getErrCodeDes() + "]";
}
}

View File

@ -6,14 +6,14 @@ import org.apache.commons.lang3.StringUtils;
import com.foxinmy.weixin4j.model.WeixinAccount;
import com.foxinmy.weixin4j.mp.payment.PayPackage;
import com.foxinmy.weixin4j.mp.payment.TradeType;
import com.foxinmy.weixin4j.mp.type.TradeType;
import com.foxinmy.weixin4j.util.RandomUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 微信支付V3<br/>
* 注意:
* <font color="red">total_fee字段传入时单位为元,创建支付时会转换为分</font>
* V3支付的订单详情<br/>
* 注意: <font color="red">total_fee字段传入时单位为元,创建支付时会转换为分</font>
*
* @className PayPackageV3
* @author jy
* @date 2014年10月21日
@ -38,22 +38,21 @@ public class PayPackageV3 extends PayPackage {
}
public PayPackageV3(WeixinAccount weixinAccount, String body,
String out_trade_no, double total_fee, String spbill_create_ip,
TradeType tradeType) {
this(weixinAccount.getAppId(), weixinAccount.getMchId(), null,
RandomUtil.generateString(16), body, null, out_trade_no,
total_fee, spbill_create_ip, null, null, null, null, tradeType,
weixinAccount.getOpenId(), null, weixinAccount.getPaySignKey());
public PayPackageV3(WeixinAccount weixinAccount, String openId,
String body, String out_trade_no, double total_fee,
String spbill_create_ip, TradeType tradeType) {
this(weixinAccount, openId, body, null, out_trade_no, total_fee,
spbill_create_ip, null, tradeType);
}
public PayPackageV3(WeixinAccount weixinAccount, String body,
String attach, String out_trade_no, double total_fee,
public PayPackageV3(WeixinAccount weixinAccount, String openId,
String body, String attach, String out_trade_no, double total_fee,
String spbill_create_ip, String notify_url, TradeType tradeType) {
this(weixinAccount.getAppId(), weixinAccount.getMchId(), null, RandomUtil
.generateString(16), body, attach, out_trade_no, total_fee,
spbill_create_ip, null, null, null, notify_url, tradeType,
weixinAccount.getOpenId(), null, weixinAccount.getPaySignKey());
this(weixinAccount.getAppId(), weixinAccount.getMchId(), weixinAccount
.getDeviceInfo(), RandomUtil.generateString(16), body, attach,
out_trade_no, total_fee, spbill_create_ip, null, null, null,
notify_url, tradeType, openId, null, weixinAccount
.getPaySignKey());
}
public PayPackageV3(String appid, String mch_id, String device_info,

View File

@ -1,7 +1,5 @@
package com.foxinmy.weixin4j.mp.payment.v3;
import java.beans.Transient;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.exception.PayException;
import com.foxinmy.weixin4j.http.XmlResult;
@ -23,13 +21,14 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
* @author jy
* @date 2014年8月17日
* @since JDK 1.7
* @see com.foxinmy.weixin4j.mp.payment.v3.PayRequestV3.PrePay
* @see com.foxinmy.weixin4j.mp.payment.v3.PrePay
*/
public class PayRequestV3 extends PayRequest {
private static final long serialVersionUID = -5972173459255255197L;
@XStreamOmitField
@JSONField(serialize = false)
private PrePay prePay;
public PayRequestV3(PrePay prePay) throws PayException {
@ -46,17 +45,16 @@ public class PayRequestV3 extends PayRequest {
this.setPackageInfo("prepay_id=" + prePay.getPrepayId());
}
@Transient
@JSONField(serialize = false)
public PrePay getPrePay() {
return prePay;
}
@Override
public String toString() {
return "PayRequestV3 [getAppId()=" + getAppId() + ", getTimeStamp()="
+ getTimeStamp() + ", getNonceStr()=" + getNonceStr()
+ ", getPackageInfo()=" + getPackageInfo() + ", getSignType()="
+ getSignType() + "]";
return "PayRequestV3 [prePay=" + prePay + ", getPackageInfo()="
+ getPackageInfo() + ", getAppId()=" + getAppId()
+ ", getTimeStamp()=" + getTimeStamp() + ", getNonceStr()="
+ getNonceStr() + ", getPaySign()=" + getPaySign()
+ ", getSignType()=" + getSignType() + "]";
}
}

View File

@ -1,11 +1,11 @@
package com.foxinmy.weixin4j.mp.payment.v3;
import com.foxinmy.weixin4j.mp.payment.ApiResult;
import com.foxinmy.weixin4j.mp.payment.TradeType;
import com.foxinmy.weixin4j.mp.type.TradeType;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 生成订单信息
* 订单信息
*
* @className PrePay
* @author jy

View File

@ -4,7 +4,6 @@ import java.util.List;
import com.foxinmy.weixin4j.mp.payment.ApiResult;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
/**
* 退款记录
@ -13,7 +12,7 @@ import com.thoughtworks.xstream.annotations.XStreamOmitField;
* @author jy
* @date 2014年11月1日
* @since JDK 1.7
* @see
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundDetail
*/
@XStreamAlias("xml")
public class Refund extends ApiResult {
@ -28,7 +27,6 @@ public class Refund extends ApiResult {
private String subMchId; //
@XStreamAlias("refund_count")
private int count;// 退款笔数
@XStreamOmitField
private List<RefundDetail> details;
public String getTransactionId() {

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.mp.payment;
package com.foxinmy.weixin4j.mp.payment.v3;
import java.lang.reflect.Field;
import java.util.HashMap;
@ -9,8 +9,6 @@ import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.foxinmy.weixin4j.mp.payment.v3.Refund;
import com.foxinmy.weixin4j.mp.payment.v3.RefundDetail;
import com.foxinmy.weixin4j.xml.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
@ -23,11 +21,13 @@ import com.thoughtworks.xstream.mapper.Mapper;
/**
* 退款查询接口调用结果转换类
*
* @className RefundConverter
* @author jy
* @date 2014年11月2日
* @since JDK 1.7
* @see
* @see com.foxinmy.weixin4j.mp.payment.v3.Refund
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundDetail
*/
public class RefundConverter {
private final static XStream xStream = XStream.get();

View File

@ -2,7 +2,7 @@ package com.foxinmy.weixin4j.mp.payment.v3;
import java.io.Serializable;
import com.foxinmy.weixin4j.mp.payment.RefundStatus;
import com.foxinmy.weixin4j.mp.type.RefundStatus;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**

View File

@ -1,8 +1,8 @@
package com.foxinmy.weixin4j.mp.response;
import java.io.Serializable;
import java.io.Writer;
import com.foxinmy.weixin4j.model.BaseMsg;
import com.foxinmy.weixin4j.mp.type.ResponseType;
import com.foxinmy.weixin4j.msg.BaseMessage;
import com.foxinmy.weixin4j.util.ClassUtil;
@ -24,7 +24,7 @@ import com.thoughtworks.xstream.io.json.JsonWriter;
* @date 2014年4月6日
* @since JDK 1.7
*/
public class BaseResponse implements Serializable {
public class BaseResponse extends BaseMsg {
private static final long serialVersionUID = 7761192742840031607L;
protected final static XStream xmlStream = XStream.get();
@ -35,12 +35,6 @@ public class BaseResponse implements Serializable {
}
});
@XStreamAlias("ToUserName")
private String toUserName; // 开发者微信号
@XStreamAlias("FromUserName")
private String fromUserName; // 发送方帐号一个OpenID
@XStreamAlias("CreateTime")
private long createTime = System.currentTimeMillis(); // 消息创建时间 整型
@XStreamAlias("MsgType")
private ResponseType msgType; // 消息类型
@ -65,33 +59,9 @@ public class BaseResponse implements Serializable {
public BaseResponse(ResponseType msgType, String toUserName,
String fromUserName) {
super(toUserName,fromUserName);
this.msgType = msgType;
this.toUserName = toUserName;
this.fromUserName = fromUserName;
}
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public ResponseType getMsgType() {
@ -108,6 +78,8 @@ public class BaseResponse implements Serializable {
* @return xml字符串
*/
public String toXml() {
Class<? extends BaseResponse> targetClass = msgType.getMessageClass();
xmlStream.alias("xml", targetClass);
return xmlStream.toXML(this);
}

View File

@ -1 +1 @@
回复消息
被动响应消息

View File

@ -1,5 +1,6 @@
package com.foxinmy.weixin4j.mp.response;
import java.beans.Transient;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@ -115,6 +116,7 @@ public class TemplateMessage implements Serializable {
+ ", data=" + data + "]";
}
@Transient
@JSONField(serialize = false)
public String toJson() {
return JSON.toJSONString(this);

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.mp.payment;
package com.foxinmy.weixin4j.mp.type;
/**
* 对账单类型

View File

@ -0,0 +1,22 @@
package com.foxinmy.weixin4j.mp.type;
/**
* 头像大小
* @className FaceSize
* @author jy
* @date 2014年11月5日
* @since JDK 1.7
* @see
*/
public enum FaceSize {
small(46), middle1(64), middle2(96), big(132);
private int size;
FaceSize(int size) {
this.size = size;
}
public int getInt() {
return size;
}
}

View File

@ -0,0 +1,23 @@
package com.foxinmy.weixin4j.mp.type;
/**
* 用户性别
* @className Gender
* @author jy
* @date 2014年11月5日
* @since JDK 1.7
* @see
*/
public enum Gender {
male(1), female(2), unknown(0);
private int sex;
Gender(int sex) {
this.sex = sex;
}
public int getInt() {
return sex;
}
}

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.mp.payment;
package com.foxinmy.weixin4j.mp.type;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.mp.payment;
package com.foxinmy.weixin4j.mp.type;
/**
* ID类型

View File

@ -0,0 +1,23 @@
package com.foxinmy.weixin4j.mp.type;
/**
* 国家地区语言版本
* @className Lang
* @author jy
* @date 2014年11月5日
* @since JDK 1.7
* @see
*/
public enum Lang {
zh_CN("简体"), zh_TW("繁体"), en("英语");
private String desc;
Lang(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
}

View File

@ -0,0 +1,23 @@
package com.foxinmy.weixin4j.mp.type;
/**
* 二维码类型
* @className QRType
* @author jy
* @date 2014年11月4日
* @since JDK 1.7
* @see
*/
public enum QRType {
TEMPORARY("QR_SCENE"), // 临时
PERMANENCE("QR_LIMIT_SCENE"); // 永久
private String name;
QRType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.mp.payment;
package com.foxinmy.weixin4j.mp.type;
/**
* 退款状态

View File

@ -10,11 +10,12 @@ import com.foxinmy.weixin4j.mp.response.VideoResponse;
import com.foxinmy.weixin4j.mp.response.VoiceResponse;
/**
*
* 响应类型
*
* @author jy.hu
*
* 被动响应类型
* @className ResponseType
* @author jy
* @date 2014年11月5日
* @since JDK 1.7
* @see
*/
public enum ResponseType {
text(TextResponse.class), image(ImageResponse.class), voice(

View File

@ -0,0 +1,13 @@
package com.foxinmy.weixin4j.mp.type;
/**
* 签名类型
* @className SignType
* @author jy
* @date 2014年11月5日
* @since JDK 1.7
* @see
*/
public enum SignType {
SHA1,MD5
}

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.mp.payment;
package com.foxinmy.weixin4j.mp.type;
/**
* 交易状态

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.mp.payment;
package com.foxinmy.weixin4j.mp.type;
/**
* 微信支付类型

View File

@ -35,12 +35,10 @@ public class MenuTest extends TokenTest {
public void create() throws WeixinException {
btnList = new ArrayList<Button>();
Button b = new Button("click");
b.setType(ButtonType.click);
b.setKey("click");
Button b = new Button("click", "name", ButtonType.click);
btnList.add(b);
b = new Button("qq", "http://www.qq.com");
b = new Button("qq", "http://www.qq.com", ButtonType.view);
btnList.add(b);
JsonResult result = menuApi.createMenu(btnList);

View File

@ -10,7 +10,6 @@ import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.mp.api.QrApi;
import com.foxinmy.weixin4j.mp.model.QRParameter;
import com.foxinmy.weixin4j.mp.model.QRParameter.QRType;
/**
* 二维码相关测试
@ -30,14 +29,14 @@ public class QRTest extends TokenTest {
@Test
public void temp_qr() throws WeixinException, IOException {
QRParameter qr = new QRParameter(1200, QRType.TEMPORARY, 2);
QRParameter qr = new QRParameter(1200, 1200);
File file = qrApi.getQR(qr);
Assert.assertTrue(file.exists());
}
@Test
public void forever_qr() throws WeixinException, IOException {
QRParameter qr = new QRParameter(QRType.PERMANENCE, 1);
QRParameter qr = new QRParameter(1200, 0);
File file = qrApi.getQR(qr);
Assert.assertTrue(file.exists());
}

View File

@ -4,7 +4,7 @@ import com.foxinmy.weixin4j.mp.response.TextResponse;
import com.foxinmy.weixin4j.msg.BaseMessage;
/**
* 返回空白消息
* 输出空白消息
*
* @className BlankAction
* @author jy.hu

View File

@ -4,7 +4,7 @@ import com.foxinmy.weixin4j.mp.response.TextResponse;
import com.foxinmy.weixin4j.msg.BaseMessage;
/**
* 显示调试信
* 调试输出用户消
*
* @className DebugAction
* @author jy

View File

@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.msg.ImageMessage;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 图片消息响应
* 图片消息处理
*
* @className ImageAction
* @author jy

View File

@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.msg.LinkMessage;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 链接消息响应
* 链接消息处理
*
* @className LinkAction
* @author jy

View File

@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.msg.LocationMessage;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 地理位置响应
* 地理位置处理
*
* @className LocationAction
* @author jy

View File

@ -13,7 +13,7 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
import com.foxinmy.weixin4j.util.MessageUtil;
/**
* 用于校验消息安全性
* 用于校验消息是否来自微信
*
* @className SignatureAction
* @author jy

View File

@ -6,7 +6,7 @@ import com.foxinmy.weixin4j.msg.TextMessage;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 文字消息响应
* 文字消息处理
*
* @className TextAction
* @author jy

View File

@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.msg.VideoMessage;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 视频消息响应
* 视频消息处理
*
* @className VideoAction
* @author jy

View File

@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.msg.VoiceMessage;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 语音消息响应
* 语音消息处理
*
* @className VoiceAction
* @author jy

View File

@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.type.EventType;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 菜单点击click事件时触发
* click类型菜单点击时触发
*
* @className MenuClickAction
* @author jy

View File

@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.type.EventType;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 菜单发送地理位置时触发
* 点击菜单发送地理位置时触发
*
* @className MenuLocationAction
* @author jy

View File

@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.type.EventType;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 菜单发送图片时触发
* 点击菜单发送图片时触发
*
* @className MenuPhotoAction
* @author jy

View File

@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.type.EventType;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 菜单扫描时触发
* 点击菜单扫描时触发
*
* @className MenuScanAction
* @author jy

View File

@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.type.EventType;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 菜单点击view事件时触发
* view类型菜单点击时触发
*
* @className MenuViewAction
* @author jy

View File

@ -13,7 +13,7 @@ import com.foxinmy.weixin4j.type.MessageType;
* @author jy
* @date 2014年10月9日
* @since JDK 1.7
* @see com.foxinmy.weixin4j.msg.event.ScanEventMessage
* @see com.foxinmy.weixin4j.msg.event.ScribeEventMessage
*/
@Action(msgType = MessageType.event, eventType = { EventType.subscribe })
public class SubscribeAction extends DebugAction<ScribeEventMessage> {

View File

@ -13,7 +13,7 @@ import com.foxinmy.weixin4j.type.MessageType;
* @author jy
* @date 2014年10月10日
* @since JDK 1.7
* @see com.foxinmy.weixin4j.msg.event.ScanEventMessage
* @see com.foxinmy.weixin4j.msg.event.ScribeEventMessage
*/
@Action(msgType = MessageType.event, eventType = { EventType.unsubscribe })
public class UnsubscribeAction extends DebugAction<ScribeEventMessage> {

View File

@ -8,16 +8,16 @@ import java.lang.annotation.Target;
import com.foxinmy.weixin4j.type.EventType;
import com.foxinmy.weixin4j.type.MessageType;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
/**
* 标注
* 标注Action类来处理消息请求
* @className Action
* @author jy
* @date 2014年10月12日
* @since JDK 1.7
* @see
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Action {
MessageType msgType();

View File

@ -0,0 +1 @@
action与消息的mapping实现

View File

@ -13,7 +13,7 @@ import java.util.ResourceBundle;
import com.foxinmy.weixin4j.mp.server.WeixinServerInitializer;
/**
* 微信服务启动程序
* 微信服务netty启动程序
*
* @className WeixinBootstrap
* @author jy