main
parent
1edf5e3e66
commit
d2ed5eda44
|
|
@ -390,7 +390,7 @@ public class PayController extends BaseController
|
||||||
miniOrderWechatPay.setTransactionid(params.get("trade_no"));
|
miniOrderWechatPay.setTransactionid(params.get("trade_no"));
|
||||||
appOrderPayMapper.insertAppOrderPay(miniOrderWechatPay);
|
appOrderPayMapper.insertAppOrderPay(miniOrderWechatPay);
|
||||||
//修改用户信息
|
//修改用户信息
|
||||||
// updateUser(appOrder);
|
updateUser(appOrder);
|
||||||
out.println("success");
|
out.println("success");
|
||||||
} else {
|
} else {
|
||||||
// TODO 验签失败则记录异常日志,并在response中返回fail.
|
// TODO 验签失败则记录异常日志,并在response中返回fail.
|
||||||
|
|
@ -521,7 +521,8 @@ public class PayController extends BaseController
|
||||||
String orderNo = KeyUtil.generateUniqueKey();
|
String orderNo = KeyUtil.generateUniqueKey();
|
||||||
AlipayTradeAppPayResponse result = null;
|
AlipayTradeAppPayResponse result = null;
|
||||||
try {
|
try {
|
||||||
result = alipayService.startPay(orderNo,appOrderArg.getPrice());
|
//result = alipayService.startPay(orderNo,appOrderArg.getPrice(),appOrderArg.getLevel() == 2 ? 30 : (appOrderArg.getLevel() == 3 ? 365 : 0));
|
||||||
|
result = alipayService.startPay(orderNo,appOrderArg.getPrice(),1);
|
||||||
} catch (AlipayApiException e) {
|
} catch (AlipayApiException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -542,4 +543,61 @@ public class PayController extends BaseController
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/aliPaySignCallback")
|
||||||
|
public void aliPaySignCallback(HttpServletRequest request, HttpServletResponse response) throws Exception{
|
||||||
|
log.info("=======>>>开始获取支付宝支付返回信息");
|
||||||
|
//获取支付宝POST过来反馈信息,将异步通知中收到的待验证所有参数都存放到map中
|
||||||
|
Map< String , String > params = new HashMap < String , String > ();
|
||||||
|
Map requestParams = request.getParameterMap();
|
||||||
|
for(Iterator iter = requestParams.keySet().iterator();iter.hasNext();){
|
||||||
|
String name = (String)iter.next();
|
||||||
|
String[] values = (String [])requestParams.get(name);
|
||||||
|
String valueStr = "";
|
||||||
|
for(int i = 0;i < values.length;i ++ ){
|
||||||
|
valueStr = (i==values.length-1)?valueStr + values [i]:valueStr + values[i] + ",";
|
||||||
|
}
|
||||||
|
//乱码解决,这段代码在出现乱码时使用。
|
||||||
|
//valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
|
||||||
|
System.out.println(name);
|
||||||
|
params.put (name,valueStr);
|
||||||
|
}
|
||||||
|
//公钥证书验签示例代码
|
||||||
|
boolean signVerified = AlipaySignature.rsaCertCheckV1(params,"/Users/wyh/Documents/code/gan/gan-modules/ruoyi-gan/src/main/resources/alipayCertPublicKey_RSA2.crt","UTF-8","RSA2");
|
||||||
|
PrintWriter out;
|
||||||
|
try {
|
||||||
|
out = response.getWriter();
|
||||||
|
if (signVerified){
|
||||||
|
// TODO 验签成功后
|
||||||
|
String outTradeNo = params.get("out_trade_no");
|
||||||
|
System.out.println(outTradeNo);
|
||||||
|
/*AppOrder appOrder = appOrderMapper.selectOneByOutTradeNo(outTradeNo);
|
||||||
|
|
||||||
|
AppOrder entity = new AppOrder();
|
||||||
|
entity.setId(appOrder.getId());
|
||||||
|
entity.setTradeNo(params.get("trade_no"));
|
||||||
|
entity.setPayStatus(2);
|
||||||
|
entity.setPayTime(new Date());
|
||||||
|
appOrderMapper.updateAppOrder(entity);
|
||||||
|
|
||||||
|
AppOrderPay miniOrderWechatPay = new AppOrderPay();
|
||||||
|
miniOrderWechatPay.setAppid(params.get("app_id"));
|
||||||
|
miniOrderWechatPay.setOuttradeno(params.get("out_trade_no"));
|
||||||
|
miniOrderWechatPay.setResultcode(params.get("trade_status"));
|
||||||
|
miniOrderWechatPay.setTimeend(params.get("gmt_payment"));
|
||||||
|
miniOrderWechatPay.setTotalfee(params.get("total_amount"));
|
||||||
|
miniOrderWechatPay.setTransactionid(params.get("trade_no"));
|
||||||
|
appOrderPayMapper.insertAppOrderPay(miniOrderWechatPay);*/
|
||||||
|
//修改用户信息
|
||||||
|
// updateUser(appOrder);
|
||||||
|
out.println("success");
|
||||||
|
} else {
|
||||||
|
// TODO 验签失败则记录异常日志,并在response中返回fail.
|
||||||
|
out.println("fail");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("异常订单:" + params.toString());
|
||||||
|
log.info("========>PrintWriter fail");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import com.alipay.api.response.AlipayTradeAppPayResponse;
|
||||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||||
import com.ruoyi.app.domain.AppOrderArg;
|
import com.ruoyi.app.domain.AppOrderArg;
|
||||||
import com.ruoyi.app.domain.dto.KeyUtil;
|
import com.ruoyi.app.domain.dto.KeyUtil;
|
||||||
|
import com.ruoyi.common.core.utils.DateUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.DataFormat;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
@ -42,6 +44,7 @@ public class AlipayService {
|
||||||
private static final String SIGN_TYPE = "RSA2";
|
private static final String SIGN_TYPE = "RSA2";
|
||||||
|
|
||||||
private static final String NOTIFY_URL = "http://139.224.213.131:7008/pay/aliPayCallback";
|
private static final String NOTIFY_URL = "http://139.224.213.131:7008/pay/aliPayCallback";
|
||||||
|
private static final String SIGN_NOTIFY_URL = "http://139.224.213.131:7008/pay/aliPaySignCallback";
|
||||||
|
|
||||||
private static final String SUBJECT = "订单充值";
|
private static final String SUBJECT = "订单充值";
|
||||||
|
|
||||||
|
|
@ -133,7 +136,7 @@ public class AlipayService {
|
||||||
// System.out.println(diagnosisUrl);
|
// System.out.println(diagnosisUrl);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
public AlipayTradeAppPayResponse startPay(String orderNo,String price) throws AlipayApiException{
|
public AlipayTradeAppPayResponse startPay(String orderNo,String price,Integer day) throws AlipayApiException{
|
||||||
try {
|
try {
|
||||||
// 1. 创建AlipayClient实例
|
// 1. 创建AlipayClient实例
|
||||||
AlipayClient alipayClient = new DefaultAlipayClient(getClientParams());
|
AlipayClient alipayClient = new DefaultAlipayClient(getClientParams());
|
||||||
|
|
@ -145,6 +148,27 @@ public class AlipayService {
|
||||||
jsonObject.put("out_trade_no" , orderNo);
|
jsonObject.put("out_trade_no" , orderNo);
|
||||||
jsonObject.put("total_amount","0.01");
|
jsonObject.put("total_amount","0.01");
|
||||||
jsonObject.put("subject","订单充值");
|
jsonObject.put("subject","订单充值");
|
||||||
|
if (day > 0) {
|
||||||
|
jsonObject.put("product_code", "CYCLE_PAY_AUTH");
|
||||||
|
JSONObject signParams = new JSONObject();
|
||||||
|
signParams.put("product_code","GENERAL_WITHHOLDING");
|
||||||
|
signParams.put("personal_product_code","CYCLE_PAY_AUTH_P");
|
||||||
|
signParams.put("sign_scene","INDUSTRY|DIGITAL_MEDIA");
|
||||||
|
signParams.put("external_agreement_no",orderNo);
|
||||||
|
|
||||||
|
JSONObject accessParams = new JSONObject();
|
||||||
|
accessParams.put("channel","QRCODEORSMS");
|
||||||
|
signParams.put("access_params",accessParams);
|
||||||
|
jsonObject.put("agreement_sign_params", signParams);
|
||||||
|
|
||||||
|
JSONObject ruleParams = new JSONObject();
|
||||||
|
ruleParams.put("period_type","DAY");
|
||||||
|
ruleParams.put("period",day);
|
||||||
|
ruleParams.put("execute_time", DateUtils.getDate());
|
||||||
|
ruleParams.put("single_amount", jsonObject.get("total_amount"));
|
||||||
|
ruleParams.put("sign_notify_url",SIGN_NOTIFY_URL);
|
||||||
|
jsonObject.put("period_rule_params", ruleParams);
|
||||||
|
}
|
||||||
request.setBizContent(jsonObject.toString());
|
request.setBizContent(jsonObject.toString());
|
||||||
// 3. 发起请求并处理响应
|
// 3. 发起请求并处理响应
|
||||||
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
|
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue