快捷搜索: 王者荣耀 脱发

Java整合微信支付V3版本APP支付

3:绑定APPID和MCHID,开放平台应用关联商户平台。可关系多个,多对多关系 获取APPID和商户号 5:没了,有了APPID、商户号 、商户证书序列号、V3Api密钥、商户私钥。就开始上手吧。 6:导入依赖
<dependency>
    <groupId>com.github.wechatpay-apiv3</groupId>
    <artifactId>wechatpay-apache-httpclient</artifactId>
    <version>0.4.7</version>
</dependency>
<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.3.10</version>
</dependency>

1.配置支付信息,工具类

/**
 * 支付参数配置
 * @author liaozan8888@163.com
 */
public interface PayConstants {
    String NOTIFY_URL = "XXXX"; //回调地址
    String MCH_ID = "XXXX"; //商户号
    String MCH_SERIAL_NO = "XXXX"; //商户证书序列号
    String API_3KEY = "XXXX";   //Api密钥
    String APP_ID = "XXXX";     //ApId
    String PACKAGE = "Sign=WXPay";  //签名国定字符串
    String privateKey = "XXXX";//商户私钥
}
/**
 * 回调签名配置
 * @author liaozan8888@163.com
 */
public class AesUtil {
    static final int KEY_LENGTH_BYTE = 32;
    static final int TAG_LENGTH_BIT = 128;
    private final byte[] aesKey;

    public AesUtil(byte[] key) {
        if (key.length != KEY_LENGTH_BYTE) {
            throw new IllegalArgumentException("无效的ApiV3Key,长度必须为32个字节");
        }
        this.aesKey = key;
    }
    public String decryptToString(byte[] associatedData, byte[] nonce, String ciphertext) throws GeneralSecurityException, IOException {
        try {
            Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");

            SecretKeySpec key = new SecretKeySpec(aesKey, "AES");
            GCMParameterSpec spec = new GCMParameterSpec(TAG_LENGTH_BIT, nonce);

            cipher.init(Cipher.DECRYPT_MODE, key, spec);
            cipher.updateAAD(associatedData);

            return new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)), "utf-8");
        } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
            throw new IllegalStateException(e);
        } catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

2.调起APP支付

经验分享 程序员 微信小程序 职场和发展