修改多商户支付
This commit is contained in:
@ -16,11 +16,11 @@ public class wxPayConfig {
|
|||||||
* @param platformCertificatePath
|
* @param platformCertificatePath
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getPublicKeyByCertificat(String platformCertificatePath)
|
public static String getPublicKeyByCertificat(String platformCertificateContent)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// 读取私钥文件内容
|
// 读取私钥文件内容
|
||||||
String platformCertificateContent = readFile(platformCertificatePath);
|
//String platformCertificateContent = readFile(platformCertificatePath);
|
||||||
// 去除私钥文件中的头尾信息
|
// 去除私钥文件中的头尾信息
|
||||||
platformCertificateContent = platformCertificateContent.replace("-----BEGIN CERTIFICATE-----", "")
|
platformCertificateContent = platformCertificateContent.replace("-----BEGIN CERTIFICATE-----", "")
|
||||||
.replace("-----END CERTIFICATE-----", "")
|
.replace("-----END CERTIFICATE-----", "")
|
||||||
@ -37,10 +37,10 @@ public class wxPayConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取微信支付公钥
|
// 获取微信支付公钥
|
||||||
public static String getPublicKey(String publicKeyPath) {
|
public static String getPublicKey(String publicKeyContent) {
|
||||||
try {
|
try {
|
||||||
// 读取私钥文件内容
|
// 读取私钥文件内容
|
||||||
String publicKeyContent = readFile(publicKeyPath);
|
//String publicKeyContent = readFile(publicKeyPath);
|
||||||
// 去除私钥文件中的头尾信息
|
// 去除私钥文件中的头尾信息
|
||||||
publicKeyContent = publicKeyContent.replace("-----BEGIN PUBLIC KEY-----", "")
|
publicKeyContent = publicKeyContent.replace("-----BEGIN PUBLIC KEY-----", "")
|
||||||
.replace("-----END PUBLIC KEY-----", "")
|
.replace("-----END PUBLIC KEY-----", "")
|
||||||
@ -53,10 +53,10 @@ public class wxPayConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取商户私钥
|
// 获取商户私钥
|
||||||
public static PrivateKey getPrivateKey(String privateKeyPath) {
|
public static PrivateKey getPrivateKey(String privateKeyContent) {
|
||||||
try {
|
try {
|
||||||
// 读取私钥文件内容
|
// 读取私钥文件内容
|
||||||
String privateKeyContent = readFile(privateKeyPath);
|
//String privateKeyContent = readFile(privateKeyPath);
|
||||||
// 去除私钥文件中的头尾信息
|
// 去除私钥文件中的头尾信息
|
||||||
privateKeyContent = privateKeyContent.replace("-----BEGIN PRIVATE KEY-----", "")
|
privateKeyContent = privateKeyContent.replace("-----BEGIN PRIVATE KEY-----", "")
|
||||||
.replace("-----END PRIVATE KEY-----", "")
|
.replace("-----END PRIVATE KEY-----", "")
|
||||||
|
@ -81,12 +81,12 @@ public class WeChatPayController extends BaseController {
|
|||||||
* 获取平台证书
|
* 获取平台证书
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ApiOperation("获取平台证书")
|
/*@ApiOperation("获取平台证书")
|
||||||
@GetMapping("/getPlatformCertificate")
|
@GetMapping("/getPlatformCertificate")
|
||||||
public AjaxResult getPlatformCertificate()
|
public AjaxResult getPlatformCertificate()
|
||||||
{
|
{
|
||||||
return success(userWechatPayService.getPlatformCertificat());
|
return success(userWechatPayService.getPlatformCertificat());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取openId
|
* 获取openId
|
||||||
@ -199,7 +199,7 @@ public class WeChatPayController extends BaseController {
|
|||||||
queryWrapper.eq("wechat_public_key_id",wechatpaySerial);
|
queryWrapper.eq("wechat_public_key_id",wechatpaySerial);
|
||||||
NgMerchants ngMerchants = ngMerchantsMapper.selectOne(queryWrapper);
|
NgMerchants ngMerchants = ngMerchantsMapper.selectOne(queryWrapper);
|
||||||
QueryWrapper queryWrappers = new QueryWrapper();
|
QueryWrapper queryWrappers = new QueryWrapper();
|
||||||
queryWrapper.eq("platform_certificate_serial_number",wechatpaySerial);
|
queryWrappers.eq("platform_certificate_serial_number",wechatpaySerial);
|
||||||
NgMerchants ngMerchants1 = ngMerchantsMapper.selectOne(queryWrappers);
|
NgMerchants ngMerchants1 = ngMerchantsMapper.selectOne(queryWrappers);
|
||||||
boolean isVerified = false;
|
boolean isVerified = false;
|
||||||
if(ngMerchants!=null){
|
if(ngMerchants!=null){
|
||||||
|
@ -25,7 +25,7 @@ public interface IUserWechatPayService {
|
|||||||
/**
|
/**
|
||||||
* 获取平台证书
|
* 获取平台证书
|
||||||
*/
|
*/
|
||||||
public Map<String,Object> getPlatformCertificat();
|
//public Map<String,Object> getPlatformCertificat();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
public static String mchId = "1503198881";
|
public static String mchId = "1503198881";
|
||||||
/** 商户API私钥文件路径 */
|
/** 商户API私钥文件路径 */
|
||||||
//public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/apiclient_key.pem";
|
//public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/apiclient_key.pem";
|
||||||
public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_apiclient_key.pem";
|
// public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_apiclient_key.pem";
|
||||||
//TODO 生产环境私钥路径
|
//TODO 生产环境私钥路径
|
||||||
//public static String privateKeyPath = "/home/soft/hzwmiot/fastbee-admin/target/damogang_apiclient_key.pem";
|
//public static String privateKeyPath = "/home/soft/hzwmiot/fastbee-admin/target/damogang_apiclient_key.pem";
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -58,7 +58,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
//微信小程序appSecret
|
//微信小程序appSecret
|
||||||
public static String appSecret="7f591f559929a3bf2dbea4e156b08ae9";
|
public static String appSecret="7f591f559929a3bf2dbea4e156b08ae9";
|
||||||
//微信支付公钥地址
|
//微信支付公钥地址
|
||||||
public static String publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
|
// public static String publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
|
||||||
//public static String publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
|
//public static String publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
|
||||||
//平台证书地址
|
//平台证书地址
|
||||||
public static String platformCertificatePath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_platformCertificate.pem";
|
public static String platformCertificatePath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_platformCertificate.pem";
|
||||||
@ -100,10 +100,11 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
reqdata.put("mchid",ngMerchants.getMchId());
|
reqdata.put("mchid",ngMerchants.getMchId());
|
||||||
reqdata.put("description",recharge.getCardnumber()+recharge.getAmount().toString());
|
reqdata.put("description",recharge.getCardnumber()+recharge.getAmount().toString());
|
||||||
reqdata.put("out_trade_no",recharge.getRechargeCode());
|
reqdata.put("out_trade_no",recharge.getRechargeCode());
|
||||||
reqdata.put("notify_url",notify_url+"/"+mchId);//"\t\n" +
|
reqdata.put("notify_url",notify_url);//"\t\n" +
|
||||||
reqdata.put("payer",payer);
|
reqdata.put("payer",payer);
|
||||||
//String Signature=getSign(reqdata);
|
//String Signature=getSign(reqdata);
|
||||||
Map<String,String> info=getSign(reqdata,"POST","/v3/pay/transactions/jsapi");
|
|
||||||
|
Map<String,String> info=getSign(reqdata,"POST","/v3/pay/transactions/jsapi",ngMerchants.getPrivateKeyPath());
|
||||||
String timeStamp=info.get("timeStamp");
|
String timeStamp=info.get("timeStamp");
|
||||||
String nonce_str=info.get("nonce_str");
|
String nonce_str=info.get("nonce_str");
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
|
|
||||||
System.out.println("Prepay ID: " + prepayId);
|
System.out.println("Prepay ID: " + prepayId);
|
||||||
result.put("prepay_id",prepayId);
|
result.put("prepay_id",prepayId);
|
||||||
result.put("paySign",getPaySign(prepayId,timeStamp,nonce_str));
|
result.put("paySign",getPaySign(prepayId,timeStamp,nonce_str,ngMerchants.getPrivateKeyPath()));
|
||||||
System.out.println("success,return body = " + prepayId);
|
System.out.println("success,return body = " + prepayId);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -168,7 +169,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
/**
|
/**
|
||||||
* 生成签名
|
* 生成签名
|
||||||
*/
|
*/
|
||||||
private Map<String,String> getSign(Map<String,Object> reqBody,String reqMethod,String url) throws Exception {
|
private Map<String,String> getSign(Map<String,Object> reqBody,String reqMethod,String url,String privateKey) throws Exception {
|
||||||
//获取时间戳
|
//获取时间戳
|
||||||
|
|
||||||
/* String reqMethod="POST";
|
/* String reqMethod="POST";
|
||||||
@ -194,7 +195,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
String signStr=reqMethod+"\n"+url+"\n"+timeStamp+"\n"+nonce_str+"\n"+reqParam +"\n";
|
String signStr=reqMethod+"\n"+url+"\n"+timeStamp+"\n"+nonce_str+"\n"+reqParam +"\n";
|
||||||
System.err.println("signStr:"+signStr);
|
System.err.println("signStr:"+signStr);
|
||||||
//String signStr=reqMethod+"\n"+url+"\n"+timeStamp+"\n"+nonce_str+"\n\n";
|
//String signStr=reqMethod+"\n"+url+"\n"+timeStamp+"\n"+nonce_str+"\n\n";
|
||||||
String sign=sign(signStr.getBytes("utf-8"));
|
String sign=sign(signStr.getBytes("utf-8"),privateKey);
|
||||||
Map<String,String> info=new HashMap<>();
|
Map<String,String> info=new HashMap<>();
|
||||||
info.put("timeStamp",timeStamp);
|
info.put("timeStamp",timeStamp);
|
||||||
info.put("nonce_str",nonce_str);
|
info.put("nonce_str",nonce_str);
|
||||||
@ -210,13 +211,13 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
/**
|
/**
|
||||||
* 生成前端所需签名
|
* 生成前端所需签名
|
||||||
*/
|
*/
|
||||||
private String getPaySign(String prepayId,String timeStamp,String nonce_str) throws Exception {
|
private String getPaySign(String prepayId,String timeStamp,String nonce_str,String privateKey) throws Exception {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用字段appId、timeStamp、nonceStr、package
|
* 使用字段appId、timeStamp、nonceStr、package
|
||||||
*/
|
*/
|
||||||
String signStr=appId+"\n"+timeStamp+"\n"+nonce_str+"\n"+"prepay_id="+prepayId+"\n";
|
String signStr=appId+"\n"+timeStamp+"\n"+nonce_str+"\n"+"prepay_id="+prepayId+"\n";
|
||||||
String sign=sign(signStr.getBytes("utf-8"));
|
String sign=sign(signStr.getBytes("utf-8"),privateKey);
|
||||||
|
|
||||||
return sign;
|
return sign;
|
||||||
}
|
}
|
||||||
@ -227,11 +228,12 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private String sign(byte[] message) throws Exception{
|
private String sign(byte[] message,String privateKeyPath) throws Exception{
|
||||||
Signature sign;
|
Signature sign;
|
||||||
sign = Signature.getInstance("SHA256withRSA");
|
sign = Signature.getInstance("SHA256withRSA");
|
||||||
//这里需要一个PrivateKey类型的参数,就是商户的私钥。
|
//这里需要一个PrivateKey类型的参数,就是商户的私钥。
|
||||||
//获取商户私钥——传商户私钥位置
|
//获取商户私钥——传商户私钥位置
|
||||||
|
|
||||||
PrivateKey privateKey = wxPayConfig.getPrivateKey(privateKeyPath);
|
PrivateKey privateKey = wxPayConfig.getPrivateKey(privateKeyPath);
|
||||||
sign.initSign(privateKey);
|
sign.initSign(privateKey);
|
||||||
sign.update(message);
|
sign.update(message);
|
||||||
@ -278,7 +280,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
/*@Override*/
|
/*@Override*/
|
||||||
public Map<String,Object> getPlatformCertificat()
|
/*public Map<String,Object> getPlatformCertificat()
|
||||||
{
|
{
|
||||||
String url="https://api.mch.weixin.qq.com/v3/certificates";
|
String url="https://api.mch.weixin.qq.com/v3/certificates";
|
||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||||
@ -353,7 +355,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user