新增企业号工程并完成【部门管理】【成员管理】【标签管理】三个接口
This commit is contained in:
@@ -46,7 +46,7 @@ weixin.properties说明
|
||||
|
||||
示例(properties中换行用右斜杆\\)
|
||||
|
||||
> account={"appId":"appId","appSecret":"appSecret",
|
||||
> account={"id":"appId","secret":"appSecret",
|
||||
> "token":"开放者的token 非必须","openId":"公众号的openid 非必须",
|
||||
> "encodingAesKey":"公众号设置了加密方式且为「安全模式」需要填入",
|
||||
> "mchId":"V3.x版本下的微信商户号",
|
||||
@@ -69,7 +69,6 @@ weixin.properties说明
|
||||
3.针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenHolder`(继承`AbstractTokenHolder`并重写`getToken`方法),默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用`RedisTokenHolder`.
|
||||
|
||||
WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenHolder());
|
||||
// weixinProxy = new WeixinProxy(new RedisTokenHolder(appid,appsecret));
|
||||
// weixinProxy = new WeixinProxy(new RedisTokenHolder(weixinAccount));
|
||||
|
||||
4.`mvn package`.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<artifactId>weixin4j-mp-api</artifactId>
|
||||
<name>weixin4j-mp-api</name>
|
||||
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-mp/weixin4j-api</url>
|
||||
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-mp/weixin4j-mp-api</url>
|
||||
<description>微信公众号API</description>
|
||||
<build>
|
||||
<finalName>weixin4j-mp-api</finalName>
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.XmlResult;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.api.CustomApi;
|
||||
import com.foxinmy.weixin4j.mp.api.GroupApi;
|
||||
import com.foxinmy.weixin4j.mp.api.HelperApi;
|
||||
@@ -45,10 +45,11 @@ import com.foxinmy.weixin4j.mp.type.BillType;
|
||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.type.AccountType;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
|
||||
/**
|
||||
* 微信服务实现
|
||||
* 微信公众平台接口实现
|
||||
*
|
||||
* @className WeixinProxy
|
||||
* @author jy.hu
|
||||
@@ -74,18 +75,18 @@ public class WeixinProxy {
|
||||
* 默认采用文件存放Token信息
|
||||
*/
|
||||
public WeixinProxy() {
|
||||
this(new FileTokenHolder());
|
||||
this(new FileTokenHolder(AccountType.MP));
|
||||
}
|
||||
|
||||
/**
|
||||
* appid,appsecret<br/>
|
||||
* appid,appsecret<br>
|
||||
* <font color="red">将无法调用支付相关接口</font>
|
||||
*
|
||||
* @param appid
|
||||
* @param appsecret
|
||||
*/
|
||||
public WeixinProxy(String appid, String appsecret) {
|
||||
this(new FileTokenHolder(appid, appsecret));
|
||||
this(new WeixinMpAccount(appid, appsecret));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +94,7 @@ public class WeixinProxy {
|
||||
*
|
||||
* @param weixinAccount
|
||||
*/
|
||||
public WeixinProxy(WeixinAccount weixinAccount) {
|
||||
public WeixinProxy(WeixinMpAccount weixinAccount) {
|
||||
this(new FileTokenHolder(weixinAccount));
|
||||
}
|
||||
|
||||
@@ -793,7 +794,7 @@ public class WeixinProxy {
|
||||
* @return 订单信息
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
*/
|
||||
*/
|
||||
public Order orderQueryV2(WeixinMpAccount weixinAccount, String outTradeNo)
|
||||
throws WeixinException {
|
||||
return payApi.orderQueryV2(outTradeNo);
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.model.SemQuery;
|
||||
import com.foxinmy.weixin4j.mp.model.SemResult;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
@@ -65,10 +65,10 @@ public class HelperApi extends BaseApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public SemResult semantic(SemQuery semQuery) throws WeixinException {
|
||||
WeixinAccount weixinAccount = tokenHolder.getAccount();
|
||||
WeixinMpAccount weixinAccount = (WeixinMpAccount) tokenHolder.getAccount();
|
||||
String semantic_uri = getRequestUri("semantic_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
semQuery.appid(weixinAccount.getAppId());
|
||||
semQuery.appid(weixinAccount.getId());
|
||||
Response response = request.post(
|
||||
String.format(semantic_uri, token.getAccessToken()),
|
||||
semQuery.toJson());
|
||||
|
||||
@@ -41,7 +41,7 @@ import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.http.SSLHttpRequest;
|
||||
import com.foxinmy.weixin4j.http.XmlResult;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.mp.payment.Refund;
|
||||
@@ -70,11 +70,11 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
*/
|
||||
public class PayApi extends BaseApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final WeixinAccount weixinAccount;
|
||||
private final WeixinMpAccount weixinAccount;
|
||||
|
||||
public PayApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
this.weixinAccount = tokenHolder.getAccount();
|
||||
this.weixinAccount = (WeixinMpAccount) tokenHolder.getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +101,7 @@ public class PayApi extends BaseApi {
|
||||
Token token = tokenHolder.getToken();
|
||||
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
param.put("appid", weixinAccount.getAppId());
|
||||
param.put("appid", weixinAccount.getId());
|
||||
param.put("appkey", weixinAccount.getPaySignKey());
|
||||
param.put("openid", openId);
|
||||
param.put("transid", transid);
|
||||
@@ -142,14 +142,14 @@ public class PayApi extends BaseApi {
|
||||
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("appid", weixinAccount.getAppId());
|
||||
obj.put("appid", weixinAccount.getId());
|
||||
obj.put("appkey", weixinAccount.getPaySignKey());
|
||||
obj.put("package", sb.toString());
|
||||
obj.put("timestamp", timestamp);
|
||||
String signature = PayUtil.paysignSha(obj, null);
|
||||
|
||||
obj.clear();
|
||||
obj.put("appid", weixinAccount.getAppId());
|
||||
obj.put("appid", weixinAccount.getId());
|
||||
obj.put("package", sb.toString());
|
||||
obj.put("timestamp", timestamp);
|
||||
obj.put("app_signature", signature);
|
||||
@@ -494,7 +494,7 @@ public class PayApi extends BaseApi {
|
||||
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());
|
||||
.name().toLowerCase(), weixinAccount.getId());
|
||||
File file = new File(String.format("%s/%s", bill_path, fileName));
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
@@ -592,7 +592,7 @@ public class PayApi extends BaseApi {
|
||||
*/
|
||||
private Map<String, String> baseMapV3(IdQuery idQuery) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appid", weixinAccount.getAppId());
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("mch_id", weixinAccount.getMchId());
|
||||
map.put("nonce_str", RandomUtil.generateString(16));
|
||||
if (StringUtils.isNotBlank(weixinAccount.getDeviceInfo())) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
@@ -39,9 +40,9 @@ public class TmplApi extends BaseApi {
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_send_uri = getRequestUri("template_send_uri");
|
||||
String para = JSON.toJSONString(tplMessage);
|
||||
Response response = request.post(
|
||||
String.format(template_send_uri, token.getAccessToken()),
|
||||
tplMessage.toJson());
|
||||
String.format(template_send_uri, token.getAccessToken()), para);
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class UserApi extends BaseApi {
|
||||
WeixinAccount weixinAccount = tokenHolder.getAccount();
|
||||
String user_token_uri = getRequestUri("sns_user_token_uri");
|
||||
Response response = request.get(String.format(user_token_uri,
|
||||
weixinAccount.getAppId(), weixinAccount.getAppSecret(), code));
|
||||
weixinAccount.getId(), weixinAccount.getSecret(), code));
|
||||
|
||||
return response.getAsObject(new TypeReference<OauthToken>() {
|
||||
});
|
||||
|
||||
@@ -55,11 +55,10 @@ public class Group implements Serializable {
|
||||
/**
|
||||
* 返回创建分组所需的json格式字符串
|
||||
*
|
||||
* @return {"group": {"id": 107, "name": "test"}}
|
||||
* @return {"group": {"name": "test"}}
|
||||
*/
|
||||
public String toCreateJson() {
|
||||
return String.format("{\"group\":{\"id\":%s,\"name\":\"%s\"}}", id,
|
||||
name);
|
||||
return String.format("{\"group\":{\"name\":\"%s\"}}", name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,8 +4,8 @@ import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.foxinmy.weixin4j.model.Gender;
|
||||
import com.foxinmy.weixin4j.mp.type.FaceSize;
|
||||
import com.foxinmy.weixin4j.mp.type.Gender;
|
||||
import com.foxinmy.weixin4j.mp.type.Lang;
|
||||
|
||||
/**
|
||||
|
||||
+17
-9
@@ -4,6 +4,7 @@ import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
||||
import com.foxinmy.weixin4j.util.ClassUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
|
||||
@@ -22,6 +23,21 @@ public class BaseNotify implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7190233634431087729L;
|
||||
|
||||
private final static XStream jsonStream = new XStream(
|
||||
new JsonHierarchicalStreamDriver() {
|
||||
public HierarchicalStreamWriter createWriter(Writer writer) {
|
||||
return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
|
||||
}
|
||||
});
|
||||
static {
|
||||
Class<?>[] classes = ClassUtil
|
||||
.getClasses(BaseNotify.class.getPackage())
|
||||
.toArray(new Class[0]);
|
||||
|
||||
jsonStream.setMode(XStream.NO_REFERENCES);
|
||||
jsonStream.autodetectAnnotations(true);
|
||||
jsonStream.processAnnotations(classes);
|
||||
}
|
||||
private String touser;
|
||||
private ResponseType msgtype;
|
||||
|
||||
@@ -56,15 +72,7 @@ public class BaseNotify implements Serializable {
|
||||
* @return {"touser": "to","msgtype": "text","text": {"content": "123"}}
|
||||
*/
|
||||
public String toJson() {
|
||||
XStream xstream = new XStream(new JsonHierarchicalStreamDriver() {
|
||||
public HierarchicalStreamWriter createWriter(Writer writer) {
|
||||
return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
|
||||
}
|
||||
});
|
||||
xstream.setMode(XStream.NO_REFERENCES);
|
||||
xstream.autodetectAnnotations(true);
|
||||
xstream.processAnnotations(this.getClass());
|
||||
return xstream.toXML(this);
|
||||
return jsonStream.toXML(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@@ -33,10 +33,10 @@ public class MicroPayPackage extends PayPackage {
|
||||
|
||||
}
|
||||
|
||||
public MicroPayPackage(WeixinAccount weixinAccount, String body,
|
||||
public MicroPayPackage(WeixinMpAccount weixinAccount, String body,
|
||||
String attach, String out_trade_no, double total_fee,
|
||||
String spbill_create_ip, String auth_code) {
|
||||
this(weixinAccount.getAppId(), weixinAccount.getMchId(), weixinAccount
|
||||
this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount
|
||||
.getDeviceInfo(), RandomUtil.generateString(16), body, attach,
|
||||
out_trade_no, total_fee, spbill_create_ip, null, null, null,
|
||||
auth_code);
|
||||
|
||||
+8
-8
@@ -12,7 +12,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.http.XmlResult;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.NativePayNotifyV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.NativePayResponseV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.PayFeedback;
|
||||
@@ -46,7 +46,7 @@ public class PayAction {
|
||||
public JSONObject jsPay() {
|
||||
JSONObject obj = new JSONObject();
|
||||
PayPackage payPackage = null;
|
||||
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
// V3 支付
|
||||
payPackage = new PayPackageV3(weixinAccount, "用户openid", "商品描述",
|
||||
"系统内部订单号", 1d, "IP地址", TradeType.JSAPI);
|
||||
@@ -111,7 +111,7 @@ public class PayAction {
|
||||
log.info("jspay_notify_orderinfo,{}", objMap);
|
||||
JsPayNotify payNotify = XStream.get(inputStream, JsPayNotify.class);
|
||||
log.info("jspay_notify_userinfo,{}", payNotify);
|
||||
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
// 验证财付通签名
|
||||
String sign = objMap.get("sign");
|
||||
objMap.remove("sign");
|
||||
@@ -153,7 +153,7 @@ public class PayAction {
|
||||
log.info("jaapi_notify_order_info:", order);
|
||||
String sign = order.getSign();
|
||||
order.setSign(null);
|
||||
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
String valid_sign = PayUtil.paysignMd5(order,
|
||||
weixinAccount.getPaySignKey());
|
||||
log.info("微信签名----->sign={},vaild_sign={}", sign, valid_sign);
|
||||
@@ -187,7 +187,7 @@ public class PayAction {
|
||||
NativePayNotifyV2 payNotify = XStream.get(inputStream,
|
||||
NativePayNotifyV2.class);
|
||||
log.info("native_pay_notify,{}", payNotify);
|
||||
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
String sign = payNotify.getPaySign();
|
||||
payNotify.setPaySign(null);
|
||||
payNotify.setSignType(null);
|
||||
@@ -227,7 +227,7 @@ public class PayAction {
|
||||
NativePayNotifyV3.class);
|
||||
String sign = payNotify.getSign();
|
||||
payNotify.setSign(null);
|
||||
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
String valid_sign = PayUtil.paysignMd5(payNotify,
|
||||
weixinAccount.getPaySignKey());
|
||||
log.info("微信签名----->sign={},vaild_sign={}", sign, valid_sign);
|
||||
@@ -272,7 +272,7 @@ public class PayAction {
|
||||
public String warning(InputStream inputStream) {
|
||||
PayWarn payWarn = XStream.get(inputStream, PayWarn.class);
|
||||
log.info("pay_warning,{}", payWarn);
|
||||
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
String sign = payWarn.getPaySign();
|
||||
payWarn.setPaySign(null);
|
||||
payWarn.setSignType(null);
|
||||
@@ -293,7 +293,7 @@ public class PayAction {
|
||||
public String feedback(InputStream inputStream) {
|
||||
PayFeedback feedback = XStream.get(inputStream, PayFeedback.class);
|
||||
log.info("pay_feedback_info:{}", feedback);
|
||||
WeixinAccount weixinAccount = ConfigUtil.getWeixinAccount();
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
// 验证微信签名
|
||||
Map<String, String> obj = new HashMap<String, String>();
|
||||
obj.put("openid", feedback.getOpenId());
|
||||
|
||||
+20
-24
@@ -13,7 +13,8 @@ import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.JsPayRequestV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.NativePayResponseV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.PayPackageV2;
|
||||
@@ -37,11 +38,6 @@ import com.foxinmy.weixin4j.xml.XStream;
|
||||
* @see
|
||||
*/
|
||||
public class PayUtil {
|
||||
private static final String UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
||||
private static final String MICROPAYURL = "https://api.mch.weixin.qq.com/pay/micropay";
|
||||
private static final String NATIVEURLV2 = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&productid=%s×tamp=%s&noncestr=%s";
|
||||
private static final String NATIVEURLV3 = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";
|
||||
|
||||
/**
|
||||
* 生成JSAPI字符串
|
||||
*
|
||||
@@ -53,7 +49,7 @@ public class PayUtil {
|
||||
* @throws PayException
|
||||
*/
|
||||
public static String createPayJsRequestJson(PayPackage payPackage,
|
||||
WeixinAccount weixinAccount) throws PayException {
|
||||
WeixinMpAccount weixinAccount) throws PayException {
|
||||
if (payPackage instanceof PayPackageV2) {
|
||||
return createPayJsRequestJsonV2((PayPackageV2) payPackage,
|
||||
weixinAccount);
|
||||
@@ -74,7 +70,7 @@ public class PayUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(PayPackageV2 payPackage,
|
||||
WeixinAccount weixinAccount) {
|
||||
WeixinMpAccount weixinAccount) {
|
||||
if (StringUtils.isBlank(payPackage.getPartner())) {
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
}
|
||||
@@ -101,7 +97,7 @@ public class PayUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(String body, String orderNo,
|
||||
double orderFee, String ip, WeixinAccount weixinAccount) {
|
||||
double orderFee, String ip, WeixinMpAccount weixinAccount) {
|
||||
PayPackageV2 payPackage = new PayPackageV2(body, orderNo, orderFee, ip);
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
return createPayJsRequestJsonV2(payPackage, weixinAccount);
|
||||
@@ -168,7 +164,7 @@ public class PayUtil {
|
||||
*/
|
||||
public static String createPayJsRequestJsonV3(String openId, String body,
|
||||
String orderNo, double orderFee, String ip, String notifyUrl,
|
||||
WeixinAccount weixinAccount) throws PayException {
|
||||
WeixinMpAccount weixinAccount) throws PayException {
|
||||
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, openId, body,
|
||||
orderNo, orderFee, ip, TradeType.JSAPI);
|
||||
payPackage.setNotify_url(notifyUrl);
|
||||
@@ -186,7 +182,7 @@ public class PayUtil {
|
||||
* @throws PayException
|
||||
*/
|
||||
public static String createPayJsRequestJsonV3(PayPackageV3 payPackage,
|
||||
WeixinAccount weixinAccount) throws PayException {
|
||||
WeixinMpAccount weixinAccount) throws PayException {
|
||||
String paySignKey = weixinAccount.getPaySignKey();
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
PrePay prePay = createPrePay(payPackage);
|
||||
@@ -201,7 +197,7 @@ public class PayUtil {
|
||||
String payJsRequestXml = XStream.to(payPackage).replaceAll("__", "_");
|
||||
HttpRequest request = new HttpRequest();
|
||||
try {
|
||||
Response response = request.post(UNIFIEDORDER, payJsRequestXml);
|
||||
Response response = request.post(Consts.UNIFIEDORDER, payJsRequestXml);
|
||||
prePay = response.getAsObject(new TypeReference<PrePay>() {
|
||||
});
|
||||
} catch (WeixinException e) {
|
||||
@@ -263,17 +259,17 @@ public class PayUtil {
|
||||
* 与订单ID等价
|
||||
* @return
|
||||
*/
|
||||
public String createNativePayRequestURLV2(WeixinAccount weixinAccount,
|
||||
public String createNativePayRequestURLV2(WeixinMpAccount weixinAccount,
|
||||
String productId) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getAppId());
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("productid", productId);
|
||||
String sign = paysignSha(map, weixinAccount.getPaySignKey());
|
||||
return String.format(NATIVEURLV2, sign, weixinAccount.getAppId(),
|
||||
return String.format(Consts.NATIVEURLV2, sign, weixinAccount.getId(),
|
||||
productId, timestamp, noncestr);
|
||||
}
|
||||
|
||||
@@ -286,29 +282,29 @@ public class PayUtil {
|
||||
* 与订单ID等价
|
||||
* @return
|
||||
*/
|
||||
public String createNativePayRequestURLV3(WeixinAccount weixinAccount,
|
||||
public String createNativePayRequestURLV3(WeixinMpAccount weixinAccount,
|
||||
String productId) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getAppId());
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("mch_id", weixinAccount.getMchId());
|
||||
map.put("time_stamp", timestamp);
|
||||
map.put("nonce_str", noncestr);
|
||||
map.put("product_id", productId);
|
||||
String sign = paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
return String.format(NATIVEURLV3, sign, weixinAccount.getAppId(),
|
||||
return String.format(Consts.NATIVEURLV3, sign, weixinAccount.getId(),
|
||||
weixinAccount.getMchId(), productId, timestamp, noncestr);
|
||||
}
|
||||
|
||||
public static String createNativePayRequestV2(WeixinAccount weixinAccount,
|
||||
public static String createNativePayRequestV2(WeixinMpAccount weixinAccount,
|
||||
PayPackageV2 payPackage) {
|
||||
NativePayResponseV2 payRequest = new NativePayResponseV2(weixinAccount,
|
||||
payPackage);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getAppId());
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("package", payRequest.getPackageInfo());
|
||||
@@ -336,12 +332,12 @@ public class PayUtil {
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 返回数据
|
||||
* @see {@link com.foxinmy.weixin4j.mp.payment.PayUtil#createMicroPay(MicroPayPackage, WeixinAccount)}
|
||||
* @see {@link com.foxinmy.weixin4j.mp.payment.PayUtil#createMicroPay(MicroPayPackage, WeixinMpAccount)}
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public static com.foxinmy.weixin4j.mp.payment.v3.Order createMicroPay(
|
||||
String authCode, String body, String attach, String orderNo,
|
||||
double orderFee, String ip, WeixinAccount weixinAccount)
|
||||
double orderFee, String ip, WeixinMpAccount weixinAccount)
|
||||
throws WeixinException {
|
||||
MicroPayPackage payPackage = new MicroPayPackage(weixinAccount, body,
|
||||
attach, orderNo, orderFee, ip, authCode);
|
||||
@@ -359,13 +355,13 @@ public class PayUtil {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public static com.foxinmy.weixin4j.mp.payment.v3.Order createMicroPay(
|
||||
MicroPayPackage payPackage, WeixinAccount weixinAccount)
|
||||
MicroPayPackage payPackage, WeixinMpAccount weixinAccount)
|
||||
throws WeixinException {
|
||||
String sign = paysignMd5(payPackage, weixinAccount.getPaySignKey());
|
||||
payPackage.setSign(sign);
|
||||
String para = XStream.to(payPackage).replaceAll("__", "_");
|
||||
HttpRequest request = new HttpRequest();
|
||||
Response response = request.post(MICROPAYURL, para);
|
||||
Response response = request.post(Consts.MICROPAYURL, para);
|
||||
return response
|
||||
.getAsObject(new TypeReference<com.foxinmy.weixin4j.mp.payment.v3.Order>() {
|
||||
});
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ import java.beans.Transient;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
|
||||
@@ -28,8 +28,8 @@ public class JsPayRequestV2 extends PayRequest {
|
||||
|
||||
private static final long serialVersionUID = -5972173459255255197L;
|
||||
|
||||
public JsPayRequestV2(WeixinAccount weixinAccount, PayPackageV2 payPackage) {
|
||||
this.setAppId(weixinAccount.getAppId());
|
||||
public JsPayRequestV2(WeixinMpAccount weixinAccount, PayPackageV2 payPackage) {
|
||||
this.setAppId(weixinAccount.getId());
|
||||
this.setPackageInfo(package2string(payPackage,
|
||||
weixinAccount.getPartnerKey()));
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ public class NativePayResponseV2 extends JsPayRequestV2 {
|
||||
@XStreamAlias("RetErrMsg")
|
||||
private String retMsg;
|
||||
|
||||
public NativePayResponseV2(WeixinAccount weixinAccount,
|
||||
public NativePayResponseV2(WeixinMpAccount weixinAccount,
|
||||
PayPackageV2 payPackage) {
|
||||
super(weixinAccount, payPackage);
|
||||
this.retCode = "0";
|
||||
|
||||
+4
-4
@@ -4,7 +4,7 @@ import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayPackage;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeType;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
@@ -38,17 +38,17 @@ public class PayPackageV3 extends PayPackage {
|
||||
|
||||
}
|
||||
|
||||
public PayPackageV3(WeixinAccount weixinAccount, String openId,
|
||||
public PayPackageV3(WeixinMpAccount 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 openId,
|
||||
public PayPackageV3(WeixinMpAccount 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(), weixinAccount
|
||||
this(weixinAccount.getId(), 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);
|
||||
|
||||
+4
-31
@@ -1,16 +1,11 @@
|
||||
package com.foxinmy.weixin4j.mp.response;
|
||||
|
||||
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;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
|
||||
import com.thoughtworks.xstream.io.json.JsonWriter;
|
||||
|
||||
/**
|
||||
* 响应消息基类
|
||||
@@ -28,26 +23,15 @@ public class BaseResponse extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = 7761192742840031607L;
|
||||
protected final static XStream xmlStream = XStream.get();
|
||||
private final static XStream jsonStream = new XStream(
|
||||
new JsonHierarchicalStreamDriver() {
|
||||
public HierarchicalStreamWriter createWriter(Writer writer) {
|
||||
return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
|
||||
}
|
||||
});
|
||||
|
||||
@XStreamAlias("MsgType")
|
||||
private ResponseType msgType; // 消息类型
|
||||
|
||||
static {
|
||||
Class<?>[] classes = ClassUtil.getClasses(
|
||||
BaseResponse.class.getPackage()).toArray(new Class[0]);
|
||||
|
||||
xmlStream.autodetectAnnotations(true);
|
||||
xmlStream.processAnnotations(classes);
|
||||
|
||||
jsonStream.setMode(XStream.NO_REFERENCES);
|
||||
jsonStream.autodetectAnnotations(true);
|
||||
jsonStream.processAnnotations(classes);
|
||||
}
|
||||
@XStreamAlias("MsgType")
|
||||
private ResponseType msgType; // 消息类型
|
||||
|
||||
public BaseResponse(ResponseType msgType) {
|
||||
this.msgType = msgType;
|
||||
@@ -59,7 +43,7 @@ public class BaseResponse extends BaseMsg {
|
||||
|
||||
public BaseResponse(ResponseType msgType, String toUserName,
|
||||
String fromUserName) {
|
||||
super(toUserName,fromUserName);
|
||||
super(toUserName, fromUserName);
|
||||
this.msgType = msgType;
|
||||
|
||||
}
|
||||
@@ -78,17 +62,6 @@ public class BaseResponse extends BaseMsg {
|
||||
* @return xml字符串
|
||||
*/
|
||||
public String toXml() {
|
||||
Class<? extends BaseResponse> targetClass = msgType.getMessageClass();
|
||||
xmlStream.alias("xml", targetClass);
|
||||
return xmlStream.toXML(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息对象转换为微信服务器接受的json格式字符串
|
||||
*
|
||||
* @return json字符串
|
||||
*/
|
||||
public String toJson() {
|
||||
return jsonStream.toXML(this);
|
||||
}
|
||||
}
|
||||
|
||||
-10
@@ -1,13 +1,9 @@
|
||||
package com.foxinmy.weixin4j.mp.response;
|
||||
|
||||
import java.beans.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* 模板消息
|
||||
*
|
||||
@@ -115,10 +111,4 @@ public class TemplateMessage implements Serializable {
|
||||
+ template_id + ", url=" + url + ", topcolor=" + topcolor
|
||||
+ ", data=" + data + "]";
|
||||
}
|
||||
|
||||
@Transient
|
||||
@JSONField(serialize = false)
|
||||
public String toJson() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# \u6d4b\u8bd5\u4e4b\u7528 \u6b63\u5f0f\u73af\u5883\u4e0bcopy\u4e00\u4efd\u5230classpath
|
||||
# \u516c\u4f17\u53f7\u4fe1\u606f
|
||||
account={"appId":"wx4ab8f8de58159a57","appSecret":"1d4eb0f4bf556aaed539f30ed05ca795",\
|
||||
account={"id":"wx4ab8f8de58159a57","secret":"1d4eb0f4bf556aaed539f30ed05ca795",\
|
||||
"token":"\u5f00\u653e\u8005\u7684token \u975e\u5fc5\u987b","openId":"\u516c\u4f17\u53f7\u7684openid \u975e\u5fc5\u987b",\
|
||||
"encodingAesKey":"\u516c\u4f17\u53f7\u8bbe\u7f6e\u4e86\u52a0\u5bc6\u65b9\u5f0f\u4e14\u4e3a\u300c\u5b89\u5168\u6a21\u5f0f\u300d\u65f6\u9700\u8981\u586b\u5165",\
|
||||
"mchId":"V3.x\u7248\u672c\u4e0b\u7684\u5fae\u4fe1\u5546\u6237\u53f7",\
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ import org.junit.Test;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.type.AccountType;
|
||||
|
||||
/**
|
||||
* token测试
|
||||
@@ -22,7 +23,7 @@ public class TokenTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
tokenHolder = new FileTokenHolder();
|
||||
tokenHolder = new FileTokenHolder(AccountType.MP);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user