Skip to content

Commit

Permalink
完善javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
spinachomes committed Jul 2, 2020
1 parent 9d9d12f commit 27651dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<excludePackageNames>com.github.rwocj.**</excludePackageNames>
<excludePackageNames>com.github.rwocj.wx.dto,com.github.rwocj.wx.properties</excludePackageNames>
</configuration>
<executions>
<execution>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/github/rwocj/wx/base/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ default String getSchema() {
* @param body 请求体,GET方法为空
* @param machId 商户Id
* @param certificateSerialNo 证书序列号
* @return 签名信息
*/
String getToken(@NonNull String method, @NonNull String url, String body, @NonNull String machId, @NonNull String certificateSerialNo);
}
13 changes: 13 additions & 0 deletions src/main/java/com/github/rwocj/wx/base/WxHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,33 @@ public interface WxHeaders {

/**
* 获取 Wechatpay-Serial header
*
* @return response header 中 Wechatpay-Serial的值
*/
String getWechatpaySerial();

/**
* @return response header 中 Wechatpay-Signature的值
*/
String getWechatpaySignature();

/**
* 微信通知请求header没有Request-ID,返回null会导致验签失败,故默认返回空字符串
* 其他实现如果不覆盖该方法影响也不大,只是验签时错误日志没有记录request_id
*
* @return response header 中Request-ID的值
*/
default String getRequestID() {
return "";
}

/**
* @return response header 中 Wechatpay-Timestamp的值
*/
String getWechatpayTimestamp();

/**
* @return response header 中 Wechatpay-Nonce的值
*/
String getWechatpayNonce();
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public WxRefundRes refund(WxRefundRequest refundRequest) throws WxPayException {
/**
* jsapi下单,封装jsapi调用支付需要的参数
* https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transactions/chapter3_8.shtml
*
* @param createOrderRequest 下单请求体
* @return 下单成功后JSAPI调用支付需要的数据
* @throws WxPayException 下单失败
*/
public JSAPICreateOrderRes createJSAPIOrder(WxCreateOrderRequest createOrderRequest) throws WxPayException {
createOrderRequest.setOrderType(OrderType.jsapi);
Expand All @@ -114,7 +118,8 @@ public JSAPICreateOrderRes createJSAPIOrder(WxCreateOrderRequest createOrderRequ
* 处理微信支付结果,请先验证签名再调用此方法
*
* @param data 微信Post过来的加密的数据
* @return
* @return 支付结果
* @throws WxPayException 处理支付结果失败,如非微信通知的支付结果
*/
public WxPayResult buildPayResult(String data) throws WxPayException {
try {
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/com/github/rwocj/wx/util/WxPayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ public class WxPayUtil {

/**
* 反序列化证书并解密
*
* @param apiV3Key v3密钥
* @param body 需要反序列化的数据
* @return 反序列化后得到的证书
* @throws IOException 非法的json数据
* @throws GeneralSecurityException 反序列化证书失败
*/
public static List<X509Certificate> deserializeToCerts(byte[] apiV3Key, String body)
throws GeneralSecurityException, IOException {
throws GeneralSecurityException, IOException {
AesUtil decryptor = new AesUtil(apiV3Key);
ObjectMapper mapper = new ObjectMapper();
JsonNode dataNode = mapper.readTree(body).get("data");
Expand All @@ -33,15 +39,15 @@ public static List<X509Certificate> deserializeToCerts(byte[] apiV3Key, String b
JsonNode encryptCertificateNode = dataNode.get(i).get("encrypt_certificate");
//解密
String cert = decryptor.decryptToString(
encryptCertificateNode.get("associated_data").toString().replaceAll("\"", "")
.getBytes(StandardCharsets.UTF_8),
encryptCertificateNode.get("nonce").toString().replaceAll("\"", "")
.getBytes(StandardCharsets.UTF_8),
encryptCertificateNode.get("ciphertext").toString().replaceAll("\"", ""));
encryptCertificateNode.get("associated_data").toString().replaceAll("\"", "")
.getBytes(StandardCharsets.UTF_8),
encryptCertificateNode.get("nonce").toString().replaceAll("\"", "")
.getBytes(StandardCharsets.UTF_8),
encryptCertificateNode.get("ciphertext").toString().replaceAll("\"", ""));

CertificateFactory cf = CertificateFactory.getInstance("X509");
X509Certificate x509Cert = (X509Certificate) cf.generateCertificate(
new ByteArrayInputStream(cert.getBytes(StandardCharsets.UTF_8))
new ByteArrayInputStream(cert.getBytes(StandardCharsets.UTF_8))
);
try {
x509Cert.checkValidity();
Expand Down

0 comments on commit 27651dd

Please sign in to comment.