mirror of
https://github.com/jeequan/jeepay
synced 2024-11-17 23:08:03 +08:00
添加支付宝当面付之扫码
This commit is contained in:
parent
2c1dc9f86d
commit
867010e1af
@ -21,6 +21,7 @@ public class PayConstant {
|
|||||||
public final static String PAY_CHANNEL_ALIPAY_MOBILE = "ALIPAY_MOBILE"; // 支付宝移动支付
|
public final static String PAY_CHANNEL_ALIPAY_MOBILE = "ALIPAY_MOBILE"; // 支付宝移动支付
|
||||||
public final static String PAY_CHANNEL_ALIPAY_PC = "ALIPAY_PC"; // 支付宝PC支付
|
public final static String PAY_CHANNEL_ALIPAY_PC = "ALIPAY_PC"; // 支付宝PC支付
|
||||||
public final static String PAY_CHANNEL_ALIPAY_WAP = "ALIPAY_WAP"; // 支付宝WAP支付
|
public final static String PAY_CHANNEL_ALIPAY_WAP = "ALIPAY_WAP"; // 支付宝WAP支付
|
||||||
|
public final static String PAY_CHANNEL_ALIPAY_QR = "ALIPAY_QR"; // 支付宝当面付之扫码支付
|
||||||
|
|
||||||
public final static String TRANS_CHANNEL_WX_APP = "TRANS_WX_APP"; // 微信APP转账
|
public final static String TRANS_CHANNEL_WX_APP = "TRANS_WX_APP"; // 微信APP转账
|
||||||
public final static String TRANS_CHANNEL_WX_JSAPI = "TRANS_WX_JSAPI"; // 微信公众号转账
|
public final static String TRANS_CHANNEL_WX_JSAPI = "TRANS_WX_JSAPI"; // 微信公众号转账
|
||||||
|
@ -75,7 +75,8 @@ public class PayChannelController {
|
|||||||
// 对于配置支付宝参数时,前端将+号转为空格bug处理
|
// 对于配置支付宝参数时,前端将+号转为空格bug处理
|
||||||
if(PayConstant.PAY_CHANNEL_ALIPAY_MOBILE.equals(channelId) ||
|
if(PayConstant.PAY_CHANNEL_ALIPAY_MOBILE.equals(channelId) ||
|
||||||
PayConstant.PAY_CHANNEL_ALIPAY_PC.equals(channelId) ||
|
PayConstant.PAY_CHANNEL_ALIPAY_PC.equals(channelId) ||
|
||||||
PayConstant.PAY_CHANNEL_ALIPAY_WAP.equals(channelId)) {
|
PayConstant.PAY_CHANNEL_ALIPAY_WAP.equals(channelId) ||
|
||||||
|
PayConstant.PAY_CHANNEL_ALIPAY_QR.equals(channelId)) {
|
||||||
JSONObject paramObj = null;
|
JSONObject paramObj = null;
|
||||||
try{
|
try{
|
||||||
paramObj = JSON.parseObject(po.getString("param"));
|
paramObj = JSON.parseObject(po.getString("param"));
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
<option value="ALIPAY_MOBILE" <#if (item.channelId!"") == "ALIPAY_MOBILE">selected="selected"</#if>>ALIPAY_MOBILE</option>
|
<option value="ALIPAY_MOBILE" <#if (item.channelId!"") == "ALIPAY_MOBILE">selected="selected"</#if>>ALIPAY_MOBILE</option>
|
||||||
<option value="ALIPAY_PC" <#if (item.channelId!"") == "ALIPAY_PC">selected="selected"</#if>>ALIPAY_PC</option>
|
<option value="ALIPAY_PC" <#if (item.channelId!"") == "ALIPAY_PC">selected="selected"</#if>>ALIPAY_PC</option>
|
||||||
<option value="ALIPAY_WAP" <#if (item.channelId!"") == "ALIPAY_WAP">selected="selected"</#if>>ALIPAY_WAP</option>
|
<option value="ALIPAY_WAP" <#if (item.channelId!"") == "ALIPAY_WAP">selected="selected"</#if>>ALIPAY_WAP</option>
|
||||||
|
<option value="ALIPAY_QR" <#if (item.channelId!"") == "ALIPAY_QR">selected="selected"</#if>>ALIPAY_QR</option>
|
||||||
<option value="WX_APP" <#if (item.channelId!"") == "WX_APP">selected="selected"</#if>>WX_APP</option>
|
<option value="WX_APP" <#if (item.channelId!"") == "WX_APP">selected="selected"</#if>>WX_APP</option>
|
||||||
<option value="WX_JSAPI" <#if (item.channelId!"") == "WX_JSAPI">selected="selected"</#if>>WX_JSAPI</option>
|
<option value="WX_JSAPI" <#if (item.channelId!"") == "WX_JSAPI">selected="selected"</#if>>WX_JSAPI</option>
|
||||||
<option value="WX_NATIVE" <#if (item.channelId!"") == "WX_NATIVE">selected="selected"</#if>>WX_NATIVE</option>
|
<option value="WX_NATIVE" <#if (item.channelId!"") == "WX_NATIVE">selected="selected"</#if>>WX_NATIVE</option>
|
||||||
|
@ -7,9 +7,11 @@ import com.alipay.api.AlipayClient;
|
|||||||
import com.alipay.api.DefaultAlipayClient;
|
import com.alipay.api.DefaultAlipayClient;
|
||||||
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
||||||
import com.alipay.api.domain.AlipayTradePagePayModel;
|
import com.alipay.api.domain.AlipayTradePagePayModel;
|
||||||
|
import com.alipay.api.domain.AlipayTradePrecreateModel;
|
||||||
import com.alipay.api.domain.AlipayTradeWapPayModel;
|
import com.alipay.api.domain.AlipayTradeWapPayModel;
|
||||||
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
||||||
import com.alipay.api.request.AlipayTradePagePayRequest;
|
import com.alipay.api.request.AlipayTradePagePayRequest;
|
||||||
|
import com.alipay.api.request.AlipayTradePrecreateRequest;
|
||||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
@ -229,4 +231,70 @@ public class PayChannel4AlipayController {
|
|||||||
map.put("payParams", payParams);
|
map.put("payParams", payParams);
|
||||||
return XXPayUtil.makeRetData(map, resKey);
|
return XXPayUtil.makeRetData(map, resKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝当面付之扫码支付
|
||||||
|
* 文档:https://docs.open.alipay.com/api_1/alipay.trade.precreate
|
||||||
|
* @param jsonParam
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/pay/channel/ali_qr")
|
||||||
|
public String doAliPayQrReq(@RequestParam String jsonParam) {
|
||||||
|
String logPrefix = "【支付宝当面付之扫码支付下单】";
|
||||||
|
JSONObject paramObj = JSON.parseObject(new String(MyBase64.decode(jsonParam)));
|
||||||
|
PayOrder payOrder = paramObj.getObject("payOrder", PayOrder.class);
|
||||||
|
String payOrderId = payOrder.getPayOrderId();
|
||||||
|
String mchId = payOrder.getMchId();
|
||||||
|
String channelId = payOrder.getChannelId();
|
||||||
|
MchInfo mchInfo = mchInfoService.selectMchInfo(mchId);
|
||||||
|
String resKey = mchInfo == null ? "" : mchInfo.getResKey();
|
||||||
|
if("".equals(resKey)) return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "", PayConstant.RETURN_VALUE_FAIL, PayEnum.ERR_0001));
|
||||||
|
PayChannel payChannel = payChannelService.selectPayChannel(channelId, mchId);
|
||||||
|
alipayConfig.init(payChannel.getParam());
|
||||||
|
AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
|
||||||
|
AlipayTradePrecreateRequest alipay_request = new AlipayTradePrecreateRequest();
|
||||||
|
// 封装请求支付信息
|
||||||
|
AlipayTradePrecreateModel model=new AlipayTradePrecreateModel();
|
||||||
|
model.setOutTradeNo(payOrderId);
|
||||||
|
model.setSubject(payOrder.getSubject());
|
||||||
|
model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
|
||||||
|
model.setBody(payOrder.getBody());
|
||||||
|
// 获取objParams参数
|
||||||
|
String objParams = payOrder.getExtra();
|
||||||
|
if (StringUtils.isNotEmpty(objParams)) {
|
||||||
|
try {
|
||||||
|
JSONObject objParamsJson = JSON.parseObject(objParams);
|
||||||
|
if(StringUtils.isNotBlank(objParamsJson.getString("discountable_amount"))) {
|
||||||
|
//可打折金额
|
||||||
|
model.setDiscountableAmount(objParamsJson.getString("discountable_amount"));
|
||||||
|
}
|
||||||
|
if(StringUtils.isNotBlank(objParamsJson.getString("undiscountable_amount"))) {
|
||||||
|
//不可打折金额
|
||||||
|
model.setUndiscountableAmount(objParamsJson.getString("undiscountable_amount"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
_log.error("{}objParams参数格式错误!", logPrefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alipay_request.setBizModel(model);
|
||||||
|
// 设置异步通知地址
|
||||||
|
alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
|
||||||
|
// 设置同步地址
|
||||||
|
alipay_request.setReturnUrl(alipayConfig.getReturn_url());
|
||||||
|
String payUrl = null;
|
||||||
|
try {
|
||||||
|
payUrl = client.execute(alipay_request).getBody();
|
||||||
|
} catch (AlipayApiException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
_log.info("{}生成跳转路径:payUrl={}", logPrefix, payUrl);
|
||||||
|
payOrderService.updateStatus4Ing(payOrderId, null);
|
||||||
|
_log.info("{}生成请求支付宝数据,req={}", logPrefix, alipay_request.getBizModel());
|
||||||
|
_log.info("###### 商户统一下单处理完成 ######");
|
||||||
|
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||||
|
map.put("payOrderId", payOrderId);
|
||||||
|
map.put("payUrl", payUrl);
|
||||||
|
return XXPayUtil.makeRetData(map, resKey);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,8 @@ public class PayOrderController {
|
|||||||
return payOrderServiceClient.doAliPayPcReq(getJsonParam("payOrder", payOrder));
|
return payOrderServiceClient.doAliPayPcReq(getJsonParam("payOrder", payOrder));
|
||||||
case PayConstant.PAY_CHANNEL_ALIPAY_WAP :
|
case PayConstant.PAY_CHANNEL_ALIPAY_WAP :
|
||||||
return payOrderServiceClient.doAliPayWapReq(getJsonParam("payOrder", payOrder));
|
return payOrderServiceClient.doAliPayWapReq(getJsonParam("payOrder", payOrder));
|
||||||
|
case PayConstant.PAY_CHANNEL_ALIPAY_QR :
|
||||||
|
return payOrderServiceClient.doAliPayQrReq(getJsonParam("payOrder", payOrder));
|
||||||
default:
|
default:
|
||||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "不支持的支付渠道类型[channelId="+channelId+"]", null, null));
|
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "不支持的支付渠道类型[channelId="+channelId+"]", null, null));
|
||||||
}
|
}
|
||||||
|
@ -89,4 +89,18 @@ public class PayOrderServiceClient {
|
|||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理支付宝当面付扫码支付
|
||||||
|
* @param jsonParam
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@HystrixCommand(fallbackMethod = "doAliPayQrReqFallback")
|
||||||
|
public String doAliPayQrReq(String jsonParam) {
|
||||||
|
return restTemplate.getForEntity("http://XXPAY-SERVICE/pay/channel/ali_qr?jsonParam=" + MyBase64.encode(jsonParam.getBytes()), String.class).getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String doAliPayQrReqFallback(String jsonParam) {
|
||||||
|
return "error";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user