代码拉取完成,页面将自动刷新
同步操作将从 小半斤拔凉/电商平台-支付 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package com.uzengroup.jkd.portal.util;
import java.util.HashMap;
import java.util.Map;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.config.AlipayConfig;
import com.alipay.util.AlipayNotify;
import com.alipay.util.AlipaySubmit;
import com.uzengroup.jkd.core.Constants;
import com.uzengroup.jkd.core.util.StringUtil;
import com.uzengroup.jkd.core.vo.MsgModel;
/**
* 支付宝支付
* @author liujun
*
*/
public class AliPayUtil {
public static final String ALI_PAY_NEW_WAP_TYPE = "QUICK_WAP_PAY"; //新手机网站支付
public static final String ALI_PAY_CLT_APP_TYPE = "QUICK_MSECURITY_PAY"; //客户端app支付
/**
* 支付宝支付在微信浏览器使用WAP网页支付
* @param outTradeNo 订单号
* @param orderTotal 支付金额
* @param body 订单支付
* @param notifyURL 回调地址
* @param returnURL 回调地址
* @return
*/
public static String getAliPayWapInfo(String outTradeNo, String orderTotal, String body, String notifyURL, String returnURL){
//把请求参数打包成数组
Map<String, String> sParaTemp = new HashMap<String, String>();
sParaTemp.put("service", AlipayConfig.service);
sParaTemp.put("partner", AlipayConfig.partner);
sParaTemp.put("seller_id", AlipayConfig.seller_id);
sParaTemp.put("_input_charset", AlipayConfig.input_charset);
sParaTemp.put("payment_type", AlipayConfig.payment_type);
sParaTemp.put("notify_url", StringUtil.null2Str(notifyURL));
sParaTemp.put("return_url", StringUtil.null2Str(returnURL));
sParaTemp.put("anti_phishing_key", AlipayConfig.anti_phishing_key);
sParaTemp.put("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
sParaTemp.put("out_trade_no", StringUtil.null2Str(outTradeNo));
sParaTemp.put("subject", StringUtil.null2Str(body));
sParaTemp.put("total_fee", StringUtil.null2Str(orderTotal));
sParaTemp.put("body", StringUtil.null2Str(body));
//其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
//如sParaTemp.put("参数名","参数值");
//建立请求
return AlipaySubmit.buildRequest(sParaTemp,"get","确认");
}
/**
* 支付宝APP客户端支付
* @param outTradeNo
* @param orderTotal
* @param body
* @param notifyURL
* @param returnURL
* @return
*/
public static String getAliPayAppInfo(String aliPayType, String outTradeNo, String orderTotal, String body, String notifyURL, String returnURL){
//JAVA服务端SDK生成APP支付订单信息示例
String appId = Constants.conf.getProperty("alipay.app.appId");
String appPrivateKey = Constants.conf.getProperty("alipay.app.private.key");
String aliPayPublicKey = Constants.conf.getProperty("alipay.app.public.key");
//实例化客户端
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", appId, appPrivateKey, "json", AlipayConfig.input_charset, aliPayPublicKey, "RSA2");
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
AlipayTradeAppPayRequest alipayRequest = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.setBody(StringUtil.null2Str(body));
model.setSubject(StringUtil.null2Str(body));
model.setOutTradeNo(outTradeNo);
model.setTimeoutExpress("30m");
model.setTotalAmount(StringUtil.null2Str(orderTotal));
model.setProductCode(StringUtil.null2Str(aliPayType));
alipayRequest.setBizModel(model);
alipayRequest.setNotifyUrl(StringUtil.null2Str(notifyURL));
alipayRequest.setReturnUrl(StringUtil.null2Str(returnURL));
try {
//这里和普通的接口调用不同,使用的是sdkExecute
if(StringUtil.compareObject(AliPayUtil.ALI_PAY_NEW_WAP_TYPE, aliPayType)){
String content = alipayClient.pageExecute(alipayRequest).getBody();
return content;
}else{
AlipayTradeAppPayResponse alipayResponse = alipayClient.sdkExecute(alipayRequest);
//就是orderString 可以直接给客户端请求,无需再做处理。
return alipayResponse.getBody();
}
} catch (AlipayApiException e) {
e.printStackTrace();
}
return null;
}
public static boolean verify(Map<String, String> params){
String aliPayPublicKey = Constants.conf.getProperty("alipay.app.public.key");
String signType = StringUtil.null2Str(params.get("sign_type"));
boolean signVerified = false;
try {
if(signType.equals("MD5")){
signVerified = AlipayNotify.verify(params);
}else{
signVerified = AlipaySignature.rsaCheckV1(params, aliPayPublicKey, AlipayConfig.input_charset, signType);
}
} catch (Exception e) {
e.printStackTrace();
}
return signVerified;
}
/**
* 支付宝APP客户端支付
* @param outTradeNo
* @param orderTotal
* @param body
* @param notifyURL
* @param returnURL
* @return
*/
public static MsgModel<String> getQueryAliPayInfo(String outTradeNo, String tradeNo){
MsgModel<String> msgModel = new MsgModel<String> ();
try{
//JAVA服务端SDK生成APP支付订单信息示例
String appId = Constants.conf.getProperty("alipay.app.appId");
String appPrivateKey = Constants.conf.getProperty("alipay.app.private.key");
String aliPayPublicKey = Constants.conf.getProperty("alipay.app.public.key");
Map<String, String> paramMap = new HashMap<String, String> ();
paramMap.put("out_trade_no", outTradeNo);
paramMap.put("trade_no", tradeNo);
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", appId, appPrivateKey, "json","GBK", aliPayPublicKey,"RSA2");
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
request.setBizContent(StringUtil.mapStrToJson(paramMap));
AlipayTradeQueryResponse response = alipayClient.execute(request);
if(response != null
&& StringUtil.nullToBoolean(response.isSuccess())
&& !StringUtil.isNull(response.getTotalAmount())){
msgModel.setIsSucc(true);
msgModel.setData(StringUtil.null2Str(response.getTotalAmount()));
return msgModel;
}
} catch (AlipayApiException e) {
e.printStackTrace();
}
msgModel.setIsSucc(false);
return msgModel;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。