Browse Source

🎨 微信支付分相关接口代码重构规范化

dev1
Binary Wang 4 years ago
parent
commit
39cea92171
17 changed files with 586 additions and 545 deletions
  1. +1
    -1
      spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/config/WxPayAutoConfiguration.java
  2. +2
    -11
      weixin-java-pay/pom.xml
  3. +36
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/Detail.java
  4. +27
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/Location.java
  5. +0
    -45
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/NotifyData.java
  6. +56
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/PayScoreNotifyData.java
  7. +31
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/PostDiscount.java
  8. +33
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/PostPayment.java
  9. +30
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/RiskFund.java
  10. +27
    -0
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/TimeRange.java
  11. +54
    -111
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequest.java
  12. +77
    -131
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreResult.java
  13. +49
    -46
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
  14. +49
    -83
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java
  15. +67
    -105
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java
  16. +1
    -12
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java
  17. +46
    -0
      weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java

+ 1
- 1
spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/config/WxPayAutoConfiguration.java View File

@@ -55,7 +55,7 @@ public class WxPayAutoConfiguration {
payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath()));
payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath()));
payConfig.setCertSerialNo(StringUtils.trimToNull(this.properties.getCertSerialNo()));
payConfig.setApiv3Key(StringUtils.trimToNull(this.properties.getApiv3Key()));
payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getApiv3Key()));

wxPayService.setConfig(payConfig);
return wxPayService;


+ 2
- 11
weixin-java-pay/pom.xml View File

@@ -82,19 +82,10 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.7</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>


</dependencies>

<profiles>


+ 36
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/Detail.java View File

@@ -0,0 +1,36 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 明细.
*
* @author doger.wang
* @date 2020-05-19
*/
@Data
@NoArgsConstructor
public class Detail implements Serializable {
private static final long serialVersionUID = -3901373259400050385L;
/**
* seq : 1
* amount : 900
* paid_type : NEWTON
* paid_time : 20091225091210
* transaction_id : 15646546545165651651
*/
@SerializedName("seq")
private int seq;
@SerializedName("amount")
private int amount;
@SerializedName("paid_type")
private String paidType;
@SerializedName("paid_time")
private String paidTime;
@SerializedName("transaction_id")
private String transactionId;
}

+ 27
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/Location.java View File

@@ -0,0 +1,27 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 服务位置信息.
*
* @author doger.wang
* @date 2020-05-19
*/
@Data
@NoArgsConstructor
public class Location implements Serializable {
private static final long serialVersionUID = -4510224826631515344L;
/**
* start_location : 嗨客时尚主题展餐厅
* end_location : 嗨客时尚主题展餐厅
*/
@SerializedName("start_location")
private String startLocation;
@SerializedName("end_location")
private String endLocation;
}

+ 0
- 45
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/NotifyData.java View File

@@ -1,45 +0,0 @@
package com.github.binarywang.wxpay.bean.payscore;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 微信支付分确认订单跟支付回调对象
* @author doger.wang
* @date 2020/5/14 12:18
*/
@NoArgsConstructor
@Data
public class NotifyData {


/**
* id : EV-2018022511223320873
* create_time : 20180225112233
* resource_type : encrypt-resource
* event_type : PAYSCORE.USER_CONFIRM
* resource : {"algorithm":"AEAD_AES_256_GCM","ciphertext":"...","nonce":"...","associated_data":""}
*/

private String id;
private String create_time;
private String resource_type;
private String event_type;
private Resource resource;

@NoArgsConstructor
@Data
public static class Resource {
/**
* algorithm : AEAD_AES_256_GCM
* ciphertext : ...
* nonce : ...
* associated_data :
*/

private String algorithm;
private String ciphertext;
private String nonce;
private String associated_data;
}
}

+ 56
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/PayScoreNotifyData.java View File

@@ -0,0 +1,56 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 微信支付分确认订单跟支付回调对象
*
* @author doger.wang
* @date 2020/5/14 12:18
*/
@NoArgsConstructor
@Data
public class PayScoreNotifyData implements Serializable {
private static final long serialVersionUID = -8538014389773390989L;

/**
* id : EV-2018022511223320873
* create_time : 20180225112233
* resource_type : encrypt-resource
* event_type : PAYSCORE.USER_CONFIRM
* resource : {"algorithm":"AEAD_AES_256_GCM","ciphertext":"...","nonce":"...","associated_data":""}
*/
@SerializedName("id")
private String id;
@SerializedName("create_time")
private String createTime;
@SerializedName("resource_type")
private String resourceType;
@SerializedName("event_type")
private String eventType;
@SerializedName("resource")
private Resource resource;

@Data
public static class Resource implements Serializable {
private static final long serialVersionUID = 8530711804335261449L;
/**
* algorithm : AEAD_AES_256_GCM
* ciphertext : ...
* nonce : ...
* associated_data :
*/
@SerializedName("algorithm")
private String algorithm;
@SerializedName("ciphertext")
private String cipherText;
@SerializedName("nonce")
private String nonce;
@SerializedName("associated_data")
private String associatedData;
}
}

+ 31
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/PostDiscount.java View File

@@ -0,0 +1,31 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 后付费商户优惠.
*
* @author doger.wang
* @date 2020-05-19
*/
@Data
@NoArgsConstructor
public class PostDiscount implements Serializable {
private static final long serialVersionUID = 2764537888242763379L;
/**
* name : 满20减1元
* description : 不与其他优惠叠加
*/
@SerializedName("name")
private String name;
@SerializedName("description")
private String description;
@SerializedName("count")
private int count;
@SerializedName("amount")
private int amount;
}

+ 33
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/PostPayment.java View File

@@ -0,0 +1,33 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 后付费项目.
*
* @author doger.wang
* @date 2020-05-19
*/
@Data
@NoArgsConstructor
public class PostPayment implements Serializable {
private static final long serialVersionUID = 2007722927556382895L;
/**
* name : 就餐费用服务费
* amount : 4000
* description : 就餐人均100元服务费:100/小时
* count : 1
*/
@SerializedName("name")
private String name;
@SerializedName("amount")
private int amount;
@SerializedName("description")
private String description;
@SerializedName("count")
private int count;
}

+ 30
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/RiskFund.java View File

@@ -0,0 +1,30 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 订单风险金信息.
*
* @author doger.wang
* @date 2020-05-19
*/
@Data
@NoArgsConstructor
public class RiskFund implements Serializable {
private static final long serialVersionUID = -3583406084396059152L;
/**
* name : ESTIMATE_ORDER_COST
* amount : 10000
* description : 就餐的预估费用
*/
@SerializedName("name")
private String name;
@SerializedName("amount")
private int amount;
@SerializedName("description")
private String description;
}

+ 27
- 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/TimeRange.java View File

@@ -0,0 +1,27 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 服务时间范围.
*
* @author doger.wang
* @date 2020-05-19
*/
@Data
@NoArgsConstructor
public class TimeRange implements Serializable {
private static final long serialVersionUID = 8169562173656314930L;
/**
* start_time : 20091225091010
* end_time : 20091225121010
*/
@SerializedName("start_time")
private String startTime;
@SerializedName("end_time")
private String endTime;
}

+ 54
- 111
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequest.java View File

@@ -1,5 +1,6 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

@@ -13,118 +14,60 @@ import java.util.List;
@NoArgsConstructor
@Data
public class WxPayScoreRequest implements Serializable {


private static final long serialVersionUID = 364764508076146082L;
/**
* out_order_no : 1234323JKHDFE1243252
* appid : wxd678efh567hg6787
* service_id : 500001
* service_introduction : 某某酒店
* post_payments : [{"name":"就餐费用服务费","amount":4000,"description":"就餐人均100元服务费:100/小时","count":1}]
* post_discounts : [{"name":"满20减1元","description":"不与其他优惠叠加"}]
* time_range : {"start_time":"20091225091010","end_time":"20091225121010"}
* location : {"start_location":"嗨客时尚主题展餐厅","end_location":"嗨客时尚主题展餐厅"}
* risk_fund : {"name":"ESTIMATE_ORDER_COST","amount":10000,"description":"就餐的预估费用"}
* attach : Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald
* notify_url : https://api.test.com
* openid : oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
* need_user_confirm : true
*/

private String out_order_no;
private String appid;
private String service_id;
private String service_introduction;
private TimeRange time_range;
private Location location;
private RiskFund risk_fund;
private String attach;
private String notify_url;
private String openid;
private boolean need_user_confirm;
private boolean profit_sharing;
private List<PostPayments> post_payments;
private List<PostDiscounts> post_discounts;
private int total_amount;
private String reason;
private String goods_tag;
private String type;
private Detail detail;

@NoArgsConstructor
@Data
public static class Detail {
private String paid_time;
}



@NoArgsConstructor
@Data
public static class TimeRange {
/**
* start_time : 20091225091010
* end_time : 20091225121010
*/

private String start_time;
private String end_time;
}
@NoArgsConstructor
@Data
public static class Location {
/**
* start_location : 嗨客时尚主题展餐厅
* end_location : 嗨客时尚主题展餐厅
*/
private String start_location;
private String end_location;
}
@NoArgsConstructor
@Data
public static class RiskFund {
/**
* name : ESTIMATE_ORDER_COST
* amount : 10000
* description : 就餐的预估费用
*/
private String name;
private int amount;
private String description;
}
@NoArgsConstructor
@Data
public static class PostPayments {
/**
* name : 就餐费用服务费
* amount : 4000
* description : 就餐人均100元服务费:100/小时
* count : 1
*/
private String name;
private int amount;
private String description;
private int count;
}
@NoArgsConstructor
@Data
public static class PostDiscounts {
/**
* name : 满20减1元
* description : 不与其他优惠叠加
*/
/**
* out_order_no : 1234323JKHDFE1243252
* appid : wxd678efh567hg6787
* service_id : 500001
* service_introduction : 某某酒店
* post_payments : [{"name":"就餐费用服务费","amount":4000,"description":"就餐人均100元服务费:100/小时","count":1}]
* post_discounts : [{"name":"满20减1元","description":"不与其他优惠叠加"}]
* time_range : {"start_time":"20091225091010","end_time":"20091225121010"}
* location : {"start_location":"嗨客时尚主题展餐厅","end_location":"嗨客时尚主题展餐厅"}
* risk_fund : {"name":"ESTIMATE_ORDER_COST","amount":10000,"description":"就餐的预估费用"}
* attach : Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald
* notify_url : https://api.test.com
* openid : oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
* need_user_confirm : true
*/
@SerializedName("out_order_no")
private String outOrderNo;
@SerializedName("appid")
private String appid;
@SerializedName("service_id")
private String serviceId;
@SerializedName("service_introduction")
private String serviceIntroduction;
@SerializedName("time_range")
private TimeRange timeRange;
@SerializedName("location")
private Location location;
@SerializedName("risk_fund")
private RiskFund riskFund;
@SerializedName("attach")
private String attach;
@SerializedName("notify_url")
private String notifyUrl;
@SerializedName("openid")
private String openid;
@SerializedName("need_user_confirm")
private boolean needUserConfirm;
@SerializedName("profit_sharing")
private boolean profitSharing;
@SerializedName("post_payments")
private List<PostPayment> postPayments;
@SerializedName("post_discounts")
private List<PostDiscount> postDiscounts;
@SerializedName("total_amount")
private int totalAmount;
@SerializedName("reason")
private String reason;
@SerializedName("goods_tag")
private String goodsTag;
@SerializedName("type")
private String type;
@SerializedName("detail")
private Detail detail;

private String name;
private String description;
private int count;
private int amount;
}
}

+ 77
- 131
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreResult.java View File

@@ -1,6 +1,6 @@
package com.github.binarywang.wxpay.bean.payscore;

import com.alibaba.fastjson.annotation.JSONField;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;

@@ -15,119 +15,78 @@ import java.util.Map;
@NoArgsConstructor
@Data
public class WxPayScoreResult implements Serializable {


private static final long serialVersionUID = 8809250065540275770L;
/**
* appid : wxd678efh567hg6787
* mchid : 1230000109
* out_order_no : 1234323JKHDFE1243252
* service_id : 500001
* service_introduction : 某某酒店
* state : CREATED
* state_description : MCH_COMPLETE
* post_payments : [{"name":"就餐费用服务费","amount":4000,"description":"就餐人均100元服务费:100/小时","count":1}]
* post_discounts : [{"name":"满20减1元","description":"不与其他优惠叠加"}]
* risk_fund : {"name":" ESTIMATE_ORDER_COST","amount":10000,"description":"就餐的预估费用"}
* time_range : {"start_time":"20091225091010","end_time":"20091225121010"}
* location : {"start_location":"嗨客时尚主题展餐厅","end_location":"嗨客时尚主题展餐厅"}
* attach : Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald
* notify_url : https://api.test.com
* order_id : 15646546545165651651
* package : DJIOSQPYWDxsjdldeuwhdodwxasd_dDiodnwjh9we
*/

private String appid;
private String mchid;
private String out_order_no;
private String service_id;
private String service_introduction;
private String state;
private String state_description;
private RiskFund risk_fund;
private TimeRange time_range;
private Location location;
private String attach;
private String notify_url;
private String order_id;
@JSONField(name = "package")
private String packageX;
private List<PostPayments> post_payments;
private List<PostDiscounts> post_discounts;
private boolean need_collection;
/**
* appid : wxd678efh567hg6787
* mchid : 1230000109
* out_order_no : 1234323JKHDFE1243252
* service_id : 500001
* service_introduction : 某某酒店
* state : CREATED
* state_description : MCH_COMPLETE
* post_payments : [{"name":"就餐费用服务费","amount":4000,"description":"就餐人均100元服务费:100/小时","count":1}]
* post_discounts : [{"name":"满20减1元","description":"不与其他优惠叠加"}]
* risk_fund : {"name":" ESTIMATE_ORDER_COST","amount":10000,"description":"就餐的预估费用"}
* time_range : {"start_time":"20091225091010","end_time":"20091225121010"}
* location : {"start_location":"嗨客时尚主题展餐厅","end_location":"嗨客时尚主题展餐厅"}
* attach : Easdfowealsdkjfnlaksjdlfkwqoi&wl3l2sald
* notify_url : https://api.test.com
* order_id : 15646546545165651651
* package : DJIOSQPYWDxsjdldeuwhdodwxasd_dDiodnwjh9we
*/
@SerializedName("appid")
private String appid;
@SerializedName("mchid")
private String mchid;
@SerializedName("out_order_no")
private String outOrderNo;
@SerializedName("service_id")
private String serviceId;
@SerializedName("service_introduction")
private String serviceIntroduction;
@SerializedName("state")
private String state;
@SerializedName("state_description")
private String stateDescription;
@SerializedName("risk_fund")
private RiskFund riskFund;
@SerializedName("time_range")
private TimeRange timeRange;
@SerializedName("location")
private Location location;
@SerializedName("attach")
private String attach;
@SerializedName("notify_url")
private String notifyUrl;
@SerializedName("order_id")
private String orderId;
@SerializedName("package")
private String packageX;
@SerializedName("post_payments")
private List<PostPayment> postPayments;
@SerializedName("post_discounts")
private List<PostDiscount> postDiscounts;
@SerializedName("need_collection")
private boolean needCollection;
/**
* 收款信息
*/
@SerializedName("collection")
private Collection collection;
//用于跳转的sign注意区分需确认模式和无需确认模式的数据差别。创单接口会返回,查询请自行组装
/**
* 用于跳转的sign注意区分需确认模式和无需确认模式的数据差别。创单接口会返回,查询请自行组装
*/
@SerializedName("payScoreSignInfo")
private Map<String, String> payScoreSignInfo;

@NoArgsConstructor
@Data
public static class RiskFund {
/**
* name : ESTIMATE_ORDER_COST
* amount : 10000
* description : 就餐的预估费用
*/

private String name;
private int amount;
private String description;
}

@NoArgsConstructor
@Data
public static class TimeRange {
/**
* start_time : 20091225091010
* end_time : 20091225121010
*/

private String start_time;
private String end_time;
}

@NoArgsConstructor
@Data
public static class Location {
/**
* start_location : 嗨客时尚主题展餐厅
* end_location : 嗨客时尚主题展餐厅
*/

private String start_location;
private String end_location;
}

@NoArgsConstructor
@Data
public static class PostPayments {
/**
* name : 就餐费用服务费
* amount : 4000
* description : 就餐人均100元服务费:100/小时
* count : 1
*/

private String name;
private int amount;
private String description;
private int count;
}

@NoArgsConstructor
@Data
public static class PostDiscounts {
/**
* name : 满20减1元
* description : 不与其他优惠叠加
*/

private String name;
private String description;
}

@NoArgsConstructor
/**
* 收款信息
*/
@Data
public static class Collection {
@NoArgsConstructor
public static class Collection implements Serializable {
private static final long serialVersionUID = 2279516555276133086L;
/**
* state : USER_PAID
* total_amount : 3900
@@ -135,29 +94,16 @@ public class WxPayScoreResult implements Serializable {
* paid_amount : 900
* details : [{"seq":1,"amount":900,"paid_type":"NEWTON","paid_time":"20091225091210","transaction_id":"15646546545165651651"}]
*/
@SerializedName("state")
private String state;
private int total_amount;
private int paying_amount;
private int paid_amount;
private List<Details> details;

@NoArgsConstructor
@Data
public static class Details {
/**
* seq : 1
* amount : 900
* paid_type : NEWTON
* paid_time : 20091225091210
* transaction_id : 15646546545165651651
*/

private int seq;
private int amount;
private String paid_type;
private String paid_time;
private String transaction_id;
}
@SerializedName("total_amount")
private int totalAmount;
@SerializedName("paying_amount")
private int payingAmount;
@SerializedName("paid_amount")
private int paidAmount;
@SerializedName("details")
private List<Detail> details;
}

}

+ 49
- 46
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java View File

@@ -9,6 +9,7 @@ import com.github.binarywang.wxpay.v3.auth.WechatPay2Validator;
import com.github.binarywang.wxpay.v3.util.PemUtils;
import lombok.Data;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.ssl.SSLContexts;
@@ -16,6 +17,7 @@ import org.apache.http.ssl.SSLContexts;
import javax.net.ssl.SSLContext;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
@@ -107,7 +109,7 @@ public class WxPayConfig {
/**
* apiV3 秘钥值.
*/
private String apiv3Key;
private String apiV3Key;

/**
* apiV3 证书序列号值
@@ -125,7 +127,7 @@ public class WxPayConfig {
*/
private String payScoreNotifyUrl;

private CloseableHttpClient apiv3HttpClient;
private CloseableHttpClient apiV3HttpClient;


/**
@@ -151,6 +153,7 @@ public class WxPayConfig {

/**
* 返回所设置的微信支付接口请求地址域名.
*
* @return 微信支付接口请求地址域名
*/
public String getPayBaseUrl() {
@@ -184,10 +187,11 @@ public class WxPayConfig {
String fileHasProblemMsg = "证书文件【" + this.getKeyPath() + "】有问题,请核实!";
String fileNotFoundMsg = "证书文件【" + this.getKeyPath() + "】不存在,请核实!";
if (this.getKeyPath().startsWith(prefix)) {
String path = StringUtils.removeFirst(this.getKeyPath(), prefix);
String path = RegExUtils.removeFirst(this.getKeyPath(), prefix);
if (!path.startsWith("/")) {
path = "/" + path;
}

inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
if (inputStream == null) {
throw new WxPayException(fileNotFoundMsg);
@@ -230,18 +234,17 @@ public class WxPayConfig {


/**
* @Author doger.wang
* @Description 初始化api v3请求头 自动签名验签
* 初始化api v3请求头 自动签名验签
* 方法参照微信官方https://github.com/wechatpay-apiv3/wechatpay-apache-httpclient
* @Date 2020/5/14 10:10
* @Param []
*
* @return org.apache.http.impl.client.CloseableHttpClient
* @author doger.wang
**/
public CloseableHttpClient initApiV3HttpClient()throws WxPayException {
public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
String privateKeyPath = this.getPrivateKeyPath();
String privateCertPath = this.getPrivateCertPath();
String certSerialNo = this.getCertSerialNo();
String apiv3Key = this.getApiv3Key();
String apiV3Key = this.getApiV3Key();
if (StringUtils.isBlank(privateKeyPath)) {
throw new WxPayException("请确保privateKeyPath已设置");
}
@@ -251,55 +254,55 @@ public class WxPayConfig {
if (StringUtils.isBlank(certSerialNo)) {
throw new WxPayException("请确保certSerialNo证书序列号已设置");
}
if (StringUtils.isBlank(apiv3Key)) {
throw new WxPayException("请确保apiv3Key值已设置");
if (StringUtils.isBlank(apiV3Key)) {
throw new WxPayException("请确保apiV3Key值已设置");
}


InputStream keyinputStream=null;
InputStream certinputStream=null;
InputStream keyInputStream = null;
InputStream certInputStream = null;
final String prefix = "classpath:";
if (privateKeyPath.startsWith(prefix)) {
String keypath = StringUtils.removeFirst(privateKeyPath, prefix);
String keypath = RegExUtils.removeFirst(privateKeyPath, prefix);
if (!keypath.startsWith("/")) {
keypath = "/" + keypath;
}
keyinputStream = WxPayConfig.class.getResourceAsStream(keypath);
if (keyinputStream == null) {
keyInputStream = WxPayConfig.class.getResourceAsStream(keypath);
if (keyInputStream == null) {
throw new WxPayException("证书文件【" + this.getPrivateKeyPath() + "】不存在,请核实!");
}
}

if (privateCertPath.startsWith(prefix)) {
String certpath = StringUtils.removeFirst(privateCertPath, prefix);
if (!certpath.startsWith("/")) {
certpath = "/" + certpath;
}
certinputStream = WxPayConfig.class.getResourceAsStream(certpath);
if (certinputStream == null) {
throw new WxPayException("证书文件【" + this.getPrivateCertPath() + "】不存在,请核实!");
}
if (privateCertPath.startsWith(prefix)) {
String certpath = RegExUtils.removeFirst(privateCertPath, prefix);
if (!certpath.startsWith("/")) {
certpath = "/" + certpath;
}
CloseableHttpClient httpClient = null;
try {
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create();
PrivateKey merchantPrivateKey = PemUtils.loadPrivateKey(keyinputStream);
X509Certificate x509Certificate = PemUtils.loadCertificate(certinputStream);
ArrayList<X509Certificate> certificates = new ArrayList<>();
certificates.add(x509Certificate);
builder.withMerchant(mchId, certSerialNo, merchantPrivateKey);
builder.withWechatpay(certificates);
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
new WechatPay2Credentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
apiv3Key.getBytes("utf-8"));
builder.withValidator(new WechatPay2Validator(verifier));
httpClient = builder.build();
this.apiv3HttpClient =httpClient;
} catch (Exception e) {
throw new WxPayException("v3请求构造异常", e);
}
return httpClient;

certInputStream = WxPayConfig.class.getResourceAsStream(certpath);
if (certInputStream == null) {
throw new WxPayException("证书文件【" + this.getPrivateCertPath() + "】不存在,请核实!");
}
}

CloseableHttpClient httpClient;
try {
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create();
PrivateKey merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream);
X509Certificate x509Certificate = PemUtils.loadCertificate(certInputStream);
ArrayList<X509Certificate> certificates = new ArrayList<>();
certificates.add(x509Certificate);
builder.withMerchant(mchId, certSerialNo, merchantPrivateKey);
builder.withWechatpay(certificates);
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
new WechatPay2Credentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
apiV3Key.getBytes(StandardCharsets.UTF_8));
builder.withValidator(new WechatPay2Validator(verifier));
httpClient = builder.build();
this.apiV3HttpClient = httpClient;
} catch (Exception e) {
throw new WxPayException("v3请求构造异常!", e);
}

return httpClient;

}
}

+ 49
- 83
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java View File

@@ -1,6 +1,6 @@
package com.github.binarywang.wxpay.service;

import com.github.binarywang.wxpay.bean.payscore.NotifyData;
import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData;
import com.github.binarywang.wxpay.bean.payscore.WxPayScoreRequest;
import com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult;
import com.github.binarywang.wxpay.exception.WxPayException;
@@ -11,154 +11,120 @@ import java.net.URISyntaxException;
* <pre>
* 支付分相关服务类.
* 微信支付分是对个人的身份特质、支付行为、使用历史等情况的综合计算分值,旨在为用户提供更简单便捷的生活方式。
* 微信用户可以在具体应用场景中,开通微信支付分。开通后,用户可以在【微信—>钱包—>支付分】中查看分数和使用记录。(即需在应用场景中使用过一次,钱包才会出现支付分入口)
* 微信用户可以在具体应用场景中,开通微信支付分。开通后,用户可以在【微信—>钱包—>支付分】中查看分数和使用记录。
* (即需在应用场景中使用过一次,钱包才会出现支付分入口)
*
* Created by doger.wang on 2020/05/12.
* </pre>
*
*
* @author doger.wang
*/
public interface PayScoreService {



/**
* <pre>
* 支付分创建订单API.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter1_1.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_1.shtml
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_1.shtml
* 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder
* </pre>
*
* @param request 请求对象
* @return WxPayScoreResult
* @return WxPayScoreResult wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxPayException;



/**
* <pre>
* 支付分查询订单API.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_2.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_2.shtml
* 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder
* </pre>
*
* @Author doger.wang
* @Description
* @Date 2020/5/14 15:40
* @Param out_order_no, query_id选填一个
* @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult
**/
WxPayScoreResult queryServiceOrder( String out_order_no,String query_id ) throws WxPayException, URISyntaxException;

* @param outOrderNo the out order no
* @param queryId the query id
* @return the wx pay score result
* @throws WxPayException the wx pay exception
* @throws URISyntaxException the uri syntax exception
*/
WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException, URISyntaxException;

/**
* <pre>
* 支付分取消订单API.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_3.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_3.shtml
* 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/cancel
* </pre>
*
* @Author doger.wang
* @Description
* @Date 2020/5/14 15:40
* @Param out_order_no reason
* @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult
**/
WxPayScoreResult cancelServiceOrder(String out_order_no, String reason) throws WxPayException;
* @param outOrderNo the out order no
* @param reason the reason
* @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult cancelServiceOrder(String outOrderNo, String reason) throws WxPayException;

/**
* <pre>
* 支付分修改订单金额API.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_4.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_4.shtml
* 接口链接:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/modify
* </pre>
*
* @Author doger.wang
* @Description
* @Date 2020/5/14 15:40
* @Param WxPayScoreRequest
* @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult
**/
* @param request the request
* @return the wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult modifyServiceOrder(WxPayScoreRequest request) throws WxPayException;


/**
* <pre>
* 支付分完结订单API.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_5.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_5.shtml
* 请求URL:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/complete
* </pre>
*
* @Author doger.wang
* @Description
* @Date 2020/5/14 15:40
* @Param WxPayScoreRequest
* @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult
**/
* @param request the request
* @return the wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult completeServiceOrder(WxPayScoreRequest request) throws WxPayException;


/**
* <pre>
* 支付分订单收款API.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_6.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_6.shtml
* 请求URL:https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/pay
*
* </pre>
*
* @Author doger.wang
* @Description
* @Date 2020/5/14 15:40
* @Param out_order_no
* @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult
**/
WxPayScoreResult payServiceOrder(String out_order_no) throws WxPayException;

* @param outOrderNo the out order no
* @return the wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult payServiceOrder(String outOrderNo) throws WxPayException;

/**
* <pre>
* 支付分订单收款API.
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_7.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter3_7.shtml
* 请求URL: https://api.mch.weixin.qq.com/v3/payscore/serviceorder/{out_order_no}/sync
* </pre>
*
* @Author doger.wang
* @Description
* @Date 2020/5/14 15:40
* @Param WxPayScoreRequest
* @return com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult
**/
* @param request the request
* @return the wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult syncServiceOrder(WxPayScoreRequest request) throws WxPayException;


/**
* <pre>
* 支付分回调内容解方法
* 支付分回调内容解方法
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml
* 接口链接:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml
* </pre>
*
* @param NotifyData 请求对象
* @return WxPayScoreResult
* @param data the data
* @return the wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult decryptNotifyData(NotifyData data) throws WxPayException;

















WxPayScoreResult parseNotifyData(PayScoreNotifyData data) throws WxPayException;

}

+ 67
- 105
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java View File

@@ -1,7 +1,6 @@
package com.github.binarywang.wxpay.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.binarywang.wxpay.bean.payscore.NotifyData;
import com.github.binarywang.wxpay.bean.payscore.PayScoreNotifyData;
import com.github.binarywang.wxpay.bean.payscore.WxPayScoreRequest;
import com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult;
import com.github.binarywang.wxpay.config.WxPayConfig;
@@ -9,11 +8,13 @@ import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.PayScoreService;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.v3.util.AesUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.URIBuilder;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.util.HashMap;
@@ -23,35 +24,31 @@ import java.util.Map;
* @author doger.wang
* @date 2020/5/14 9:43
*/
@RequiredArgsConstructor
public class PayScoreServiceImpl implements PayScoreService {
private WxPayService payService;

public PayScoreServiceImpl(WxPayService payService) {
this.payService = payService;
}

private static final Gson GSON = new GsonBuilder().create();
private final WxPayService payService;

@Override
public WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxPayException {
boolean need_user_confirm = request.isNeed_user_confirm();
boolean needUserConfirm = request.isNeedUserConfirm();
WxPayConfig config = this.payService.getConfig();
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder";
request.setAppid(config.getAppId());
request.setService_id(config.getServiceId());
request.setNotify_url(config.getPayScoreNotifyUrl());
String result = payService.postV3(url, JSONObject.toJSONString(request));
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(result, WxPayScoreResult.class);
request.setServiceId(config.getServiceId());
request.setNotifyUrl(config.getPayScoreNotifyUrl());
String result = payService.postV3(url, GSON.toJson(request));
WxPayScoreResult wxPayScoreCreateResult = GSON.fromJson(result, WxPayScoreResult.class);

//补充算一下签名给小程序跳转用
String currentTimeMillis = System.currentTimeMillis() + "";
Map<String, String> signMap = new HashMap<>();
Map<String, String> signMap = new HashMap<>(8);
signMap.put("mch_id", config.getMchId());
if (need_user_confirm){
if (needUserConfirm) {
signMap.put("package", wxPayScoreCreateResult.getPackageX());
}else {
} else {
signMap.put("service_id", config.getServiceId());
signMap.put("out_order_no", request.getOut_order_no());
signMap.put("out_order_no", request.getOutOrderNo());
}
signMap.put("timestamp", currentTimeMillis);
signMap.put("nonce_str", currentTimeMillis);
@@ -63,131 +60,96 @@ public class PayScoreServiceImpl implements PayScoreService {
}

@Override
public WxPayScoreResult queryServiceOrder(String out_order_no, String query_id) throws WxPayException, URISyntaxException {
public WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException, URISyntaxException {
WxPayConfig config = this.payService.getConfig();
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder";
URIBuilder uriBuilder = new URIBuilder(url);
if (StringUtils.isAllEmpty(out_order_no,query_id) || !StringUtils.isAnyEmpty(out_order_no,query_id)){
URIBuilder uriBuilder = new URIBuilder(url);
if (StringUtils.isAllEmpty(outOrderNo, queryId) || !StringUtils.isAnyEmpty(outOrderNo, queryId)) {
throw new WxPayException("out_order_no,query_id不允许都填写或都不填写");
}
if (StringUtils.isNotEmpty(out_order_no)){
uriBuilder.setParameter("out_order_no", out_order_no);
if (StringUtils.isNotEmpty(outOrderNo)) {
uriBuilder.setParameter("out_order_no", outOrderNo);
}
if (StringUtils.isNotEmpty(query_id)){
uriBuilder.setParameter("query_id", query_id);
if (StringUtils.isNotEmpty(queryId)) {
uriBuilder.setParameter("query_id", queryId);
}
uriBuilder.setParameter("service_id", config.getServiceId());
uriBuilder.setParameter("appid", config.getAppId());
URI build = uriBuilder.build();
String result = payService.getV3(build);
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(result, WxPayScoreResult.class);
//补充一下加密跳转信息
/* String currentTimeMillis = System.currentTimeMillis() + "";
Map<String, String> signMap = new HashMap();
signMap.put("mch_id", config.getMchId());
signMap.put("service_id", config.getServiceId());
signMap.put("out_order_no", out_order_no);
signMap.put("timestamp", currentTimeMillis);
signMap.put("nonce_str", currentTimeMillis);
signMap.put("sign_type", "HMAC-SHA256");
String sign = AesUtil.createSign(signMap, config.getMchKey());
signMap.put("sign", sign);
wxPayScoreCreateResult.setPayScoreSignInfo(signMap);*/
return wxPayScoreCreateResult;

String result = payService.getV3(uriBuilder.build());
return GSON.fromJson(result, WxPayScoreResult.class);
}



@Override
public WxPayScoreResult cancelServiceOrder(String out_order_no, String reason) throws WxPayException {
public WxPayScoreResult cancelServiceOrder(String outOrderNo, String reason) throws WxPayException {
WxPayConfig config = this.payService.getConfig();
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder/"+out_order_no+"/cancel";
HashMap<String, Object> map = new HashMap<>();
map.put("appid",config.getAppId());
map.put("service_id",config.getServiceId());
map.put("reason",reason);
String result = payService.postV3(url, JSONObject.toJSONString(map));
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(result, WxPayScoreResult.class);
return wxPayScoreCreateResult;

String url = String.format("%s/v3/payscore/serviceorder/%s/cancel", this.payService.getPayBaseUrl(), outOrderNo);
HashMap<String, Object> map = new HashMap<>(4);
map.put("appid", config.getAppId());
map.put("service_id", config.getServiceId());
map.put("reason", reason);
String result = payService.postV3(url, GSON.toJson(map));
return GSON.fromJson(result, WxPayScoreResult.class);
}

@Override
public WxPayScoreResult modifyServiceOrder(WxPayScoreRequest request) throws WxPayException {
WxPayConfig config = this.payService.getConfig();
String out_order_no = request.getOut_order_no();
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder/"+out_order_no+"/modify";
String outOrderNo = request.getOutOrderNo();
String url = String.format("%s/v3/payscore/serviceorder/%s/modify", this.payService.getPayBaseUrl(), outOrderNo);
request.setAppid(config.getAppId());
request.setService_id(config.getServiceId());
request.setOut_order_no(null);
//request.setNotify_url(config.getPayScoreNotifyUrl());
String result = payService.postV3(url, JSONObject.toJSONString(request));
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(result, WxPayScoreResult.class);
return wxPayScoreCreateResult;


request.setServiceId(config.getServiceId());
request.setOutOrderNo(null);
String result = payService.postV3(url, GSON.toJson(request));
return GSON.fromJson(result, WxPayScoreResult.class);
}

@Override
public WxPayScoreResult completeServiceOrder(WxPayScoreRequest request) throws WxPayException {
WxPayConfig config = this.payService.getConfig();
String out_order_no = request.getOut_order_no();
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder/"+out_order_no+"/complete";
String outOrderNo = request.getOutOrderNo();
String url = String.format("%s/v3/payscore/serviceorder/%s/complete", this.payService.getPayBaseUrl(), outOrderNo);
request.setAppid(config.getAppId());
request.setService_id(config.getServiceId());
//request.setNotify_url(config.getPayScoreNotifyUrl());
request.setOut_order_no(null);
String result = payService.postV3(url, JSONObject.toJSONString(request));
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(result, WxPayScoreResult.class);
return wxPayScoreCreateResult;

request.setServiceId(config.getServiceId());
request.setOutOrderNo(null);
String result = payService.postV3(url, GSON.toJson(request));
return GSON.fromJson(result, WxPayScoreResult.class);
}

@Override
public WxPayScoreResult payServiceOrder(String out_order_no) throws WxPayException {
public WxPayScoreResult payServiceOrder(String outOrderNo) throws WxPayException {
WxPayConfig config = this.payService.getConfig();
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder/"+out_order_no+"/pay";
HashMap<String, Object> map = new HashMap<>();
map.put("appid",config.getAppId());
map.put("service_id",config.getServiceId());
String result = payService.postV3(url, JSONObject.toJSONString(map));
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(result, WxPayScoreResult.class);
return wxPayScoreCreateResult;

String url = String.format("%s/v3/payscore/serviceorder/%s/pay", this.payService.getPayBaseUrl(), outOrderNo);
HashMap<String, Object> map = new HashMap<>(2);
map.put("appid", config.getAppId());
map.put("service_id", config.getServiceId());
String result = payService.postV3(url, GSON.toJson(map));
return GSON.fromJson(result, WxPayScoreResult.class);
}

@Override
public WxPayScoreResult syncServiceOrder(WxPayScoreRequest request) throws WxPayException {
WxPayConfig config = this.payService.getConfig();
String out_order_no = request.getOut_order_no();
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder/"+out_order_no+"/sync";
String outOrderNo = request.getOutOrderNo();
String url = String.format("%s/v3/payscore/serviceorder/%s/sync", this.payService.getPayBaseUrl(), outOrderNo);
request.setAppid(config.getAppId());
request.setService_id(config.getServiceId());
request.setOut_order_no(null);
//request.setNotify_url(config.getPayScoreNotifyUrl());
String result = payService.postV3(url, JSONObject.toJSONString(request));
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(result, WxPayScoreResult.class);
return wxPayScoreCreateResult;

request.setServiceId(config.getServiceId());
request.setOutOrderNo(null);
String result = payService.postV3(url, GSON.toJson(request));
return GSON.fromJson(result, WxPayScoreResult.class);
}

@Override
public WxPayScoreResult decryptNotifyData(NotifyData data) throws WxPayException{
NotifyData.Resource resource = data.getResource();
String ciphertext = resource.getCiphertext();
String associated_data = resource.getAssociated_data();
public WxPayScoreResult parseNotifyData(PayScoreNotifyData data) throws WxPayException {
PayScoreNotifyData.Resource resource = data.getResource();
String cipherText = resource.getCipherText();
String associatedData = resource.getAssociatedData();
String nonce = resource.getNonce();
String apiv3Key = this.payService.getConfig().getApiv3Key();
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String s = AesUtils.decryptToString(associated_data, nonce, ciphertext, apiv3Key);
WxPayScoreResult wxPayScoreCreateResult = JSONObject.parseObject(s, WxPayScoreResult.class);
return wxPayScoreCreateResult;
} catch (GeneralSecurityException e) {
throw new WxPayException("解析报文异常",e);
} catch (IOException e) {
throw new WxPayException("解析报文异常",e);
String s = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
return GSON.fromJson(s, WxPayScoreResult.class);
} catch (GeneralSecurityException | IOException e) {
throw new WxPayException("解析报文异常!", e);
}

}
}

+ 1
- 12
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java View File

@@ -1,18 +1,11 @@
package com.github.binarywang.wxpay.service.impl;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLContext;

import com.alibaba.fastjson.JSONObject;
import com.github.binarywang.wxpay.bean.WxPayApiData;
import com.github.binarywang.wxpay.bean.request.WxPayQueryCommentRequest;
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
import com.github.binarywang.wxpay.bean.result.WxPayCommonResult;
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import jodd.util.Base64;
import org.apache.commons.lang3.StringUtils;
@@ -35,10 +28,6 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.github.binarywang.wxpay.bean.WxPayApiData;
import com.github.binarywang.wxpay.exception.WxPayException;
import jodd.util.Base64;

/**
* <pre>
* 微信支付请求实现类,apache httpclient实现.
@@ -158,7 +147,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
}

private CloseableHttpClient createApiV3HttpClient() throws WxPayException {
CloseableHttpClient apiv3HttpClient = this.getConfig().getApiv3HttpClient();
CloseableHttpClient apiv3HttpClient = this.getConfig().getApiV3HttpClient();
if (null==apiv3HttpClient){
return this.getConfig().initApiV3HttpClient();
}


+ 46
- 0
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java View File

@@ -0,0 +1,46 @@
package com.github.binarywang.wxpay.service.impl;

import org.testng.annotations.Test;

import static org.testng.Assert.*;

/**
* 测试代码,待补充完善.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-05-19
*/
public class PayScoreServiceImplTest {

@Test
public void testCreateServiceOrder() {
}

@Test
public void testQueryServiceOrder() {
}

@Test
public void testCancelServiceOrder() {
}

@Test
public void testModifyServiceOrder() {
}

@Test
public void testCompleteServiceOrder() {
}

@Test
public void testPayServiceOrder() {
}

@Test
public void testSyncServiceOrder() {
}

@Test
public void testDecryptNotifyData() {
}
}

Loading…
Cancel
Save