修改多商户支付
This commit is contained in:
@ -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";
|
||||
/** 商户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/damogang_apiclient_key.pem";
|
||||
// public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_apiclient_key.pem";
|
||||
//TODO 生产环境私钥路径
|
||||
//public static String privateKeyPath = "/home/soft/hzwmiot/fastbee-admin/target/damogang_apiclient_key.pem";
|
||||
@Autowired
|
||||
@ -58,7 +58,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
||||
//微信小程序appSecret
|
||||
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 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("description",recharge.getCardnumber()+recharge.getAmount().toString());
|
||||
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);
|
||||
//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 nonce_str=info.get("nonce_str");
|
||||
|
||||
@ -145,7 +146,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
||||
|
||||
System.out.println("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);
|
||||
|
||||
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";
|
||||
@ -194,7 +195,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
||||
String signStr=reqMethod+"\n"+url+"\n"+timeStamp+"\n"+nonce_str+"\n"+reqParam +"\n";
|
||||
System.err.println("signStr:"+signStr);
|
||||
//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<>();
|
||||
info.put("timeStamp",timeStamp);
|
||||
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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@ -227,11 +228,12 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private String sign(byte[] message) throws Exception{
|
||||
private String sign(byte[] message,String privateKeyPath) throws Exception{
|
||||
Signature sign;
|
||||
sign = Signature.getInstance("SHA256withRSA");
|
||||
//这里需要一个PrivateKey类型的参数,就是商户的私钥。
|
||||
//获取商户私钥——传商户私钥位置
|
||||
|
||||
PrivateKey privateKey = wxPayConfig.getPrivateKey(privateKeyPath);
|
||||
sign.initSign(privateKey);
|
||||
sign.update(message);
|
||||
@ -278,7 +280,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
||||
* @return
|
||||
*/
|
||||
/*@Override*/
|
||||
public Map<String,Object> getPlatformCertificat()
|
||||
/*public Map<String,Object> getPlatformCertificat()
|
||||
{
|
||||
String url="https://api.mch.weixin.qq.com/v3/certificates";
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
@ -353,7 +355,7 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user