1.api
2. String result = AlipayUtils.fundAuthOrderAppFreeze("xxxx",orderNo,StringUtil.getUUID(),orderRealCost, AlipayBusiTypeEnum.ALPAY200);
aliMap.put("result", result);微信
3. public enum AlipayBusiTypeEnum implements Serializable{
ALPAY100("ALPAY100","ZF","xxxxx"),
ALPAY200("ALPAY200","YSQDJ","xxxx"),
ALPAY300("ALPAY300","YSQDJZZF","xxxx"),
ALPAY301("ALPAY301","YSQDJZZF","xxxx"),
ALPAY302("ALPAY302","YSQDJZZF","xxxx"),
ALPAY303("ALPAY303","YSQDJZZF","xxxx"),
ALPAY400("ALPAY400","YSQJD","xxxx"),
ALPAY401("ALPAY401","YSQJD","xxxx"),
ALPAY500("ALPAY500","ZFTK","xxxx"),
ALPAY600("ALPAY600","YSQTKJD","xxxx");app
private String busiTypeCode;
private String busiTypeName;
private String busiTypeDesc;
AlipayBusiTypeEnum(String busiTypeCode,String busiTypeName, String busiTypeDesc){
this.busiTypeCode = busiTypeCode;
this.busiTypeName = busiTypeName;
this.busiTypeDesc = busiTypeDesc;
}dom
public String getBusiTypeCode(){
return this.busiTypeCode;
}異步
public String getBusiTypeName(){
return this.busiTypeName;
}ui
public String getBusiTypeDesc(){
return this.busiTypeDesc;
}
}
this
4. 3d
public static String fundAuthOrderAppFreeze(String orderTitle,String orderNo,String requestNo,String amount,AlipayBusiTypeEnum busiType) {
//處理訂單號發到支付寶惟一的問題
String outOrderNo = orderNo + Long.toString(System.currentTimeMillis());
String alipaySeller = ConfigUtil.getSettings("alipay_seller");
String alipayLoginid = ConfigUtil.getSettings("alipay_loginid");
AlipayClient alipayClient = getAlipayClient();
AlipayFundAuthOrderAppFreezeRequest request = new AlipayFundAuthOrderAppFreezeRequest();
AlipayFundAuthOrderAppFreezeModel model = new AlipayFundAuthOrderAppFreezeModel();
model.setOrderTitle(orderTitle);
model.setOutOrderNo(outOrderNo);// 商戶受權資金訂單號 ,不能包含除中文、英文、數字之外的字符,建立後不能修改,須要保證在商戶端不重複。
model.setOutRequestNo(requestNo);// 商戶本次資金操做的請求流水號,用於標示請求流水的惟一性,不能包含除中文、英文、數字之外的字符,須要保證在商戶端不重複。
model.setPayeeUserId(alipaySeller);// 收款方的支付寶惟一用戶號,以2088開頭的16位純數字組成,若是非空則會在支付時校驗交易的的收款方與此是否一致,若是商戶有勾選花唄渠道,收款方支付寶登陸號(payee_logon_id)和用戶號(payee_user_id)不能同時爲空。
model.setPayeeLogonId(alipayLoginid);// 收款方支付寶帳號(Email或手機號),若是收款方支付寶登陸號(payee_logon_id)和用戶號(payee_user_id)同時傳遞,則以用戶號(payee_user_id)爲準,若是商戶有勾選花唄渠道,收款方支付寶登陸號(payee_logon_id)和用戶號(payee_user_id)不能同時爲空。
model.setProductCode("PRE_AUTH_ONLINE");//PRE_AUTH_ONLINE爲固定值,不要替換
model.setAmount(amount);//須要凍結的金額,單位爲:元(人民幣),精確到小數點後兩位 取值範圍:[0.01,100000000.00]
//須要支持信用受權,該字段必傳
model.setExtraParam("{\"category\":\"TIME_SHARE_RENT_CAR\",\"outStoreCode\":\"\",\"outStoreAlias\":\"租車費用\"}");
//選填字段,指定支付渠道
//model.setEnablePayChannels("[{\"payChannelType\":\"PCREDIT_PAY\"},{\"payChannelType\":\"MONEY_FUND\"},{\"payChannelType\":\"CREDITZHIMA\"}]");//餘額寶(MONEY_FUND)、花唄(PCREDIT_PAY)以及芝麻信用(CREDITZHIMA)
model.setPayTimeout("5m");
request.setBizModel(model);
String notifyUrl = ConfigUtil.getSettings("pament_domain")+"/api/pay/alipaycallback/" + busiType.getBusiTypeCode() + "/dealBusinessForAlipayCallback.do";
request.setNotifyUrl(notifyUrl);//異步通知地址,必填,該接口只經過該參數進行異步通知
String result = "";
try {
AlipayFundAuthOrderAppFreezeResponse response = alipayClient.sdkExecute(request);//注意這裏是sdkExecute,能夠獲取簽名參數
if(response.isSuccess()){
logger.info("訂單:"+orderNo+"支付寶線上資金受權凍結成功==>"+response.getBody());
result = response.getBody();
} else {
logger.info("訂單:"+orderNo+"支付寶線上資金受權凍結失敗");
}
//處理交易流水記錄
BaseMapEntity waterMap = new BaseMapEntity();
waterMap.put("className", "com.ds.tech.service.util.alibaba.AlipayUtils");
waterMap.put("methodName", "fundAuthOrderAppFreeze");
waterMap.put("tradeType", "2"); //交易方式:1.銀行卡 2.支付寶 3.微信
waterMap.put("tradeInput", JSONObject.toJSON(request).toString());
waterMap.put("tradeOutput", JSONObject.toJSON(response).toString());
waterMap.put("tradeTime", new Date());
userPurseWaterHisMapper.insertUserPurseWaterHistory(waterMap);
}catch (AlipayApiException e){
logger.info(ExceptionUtil.getExceptionStr("訂單:"+orderNo+"支付寶線上資金受權凍結失敗",e));
}blog
return result;
}接口
5. @RequestMapping(value = "/{busiTypeCode}/dealBusinessForAlipayCallback")
public void dealBusinessForAlipayCallback(@PathVariable("busiTypeCode") String busiTypeCode, HttpServletRequest request, HttpServletResponse respone) {
alipayCallbackService.dealBusinessForAlipayCallback(busiTypeCode,request,respone);
}
6.
public void dealBusinessForAlipayCallback(String busiTypeCode,HttpServletRequest request, HttpServletResponse respone){
logger.info("支付寶異步回調開始,業務類型busiTypeCode=" + busiTypeCode);
try{
PrintWriter out = respone.getWriter();
Map<String, String> params = new HashMap<String, String>();
Map<String, String[]> requestParams = request.getParameterMap();
if (requestParams.size() == 0) {
logger.info("支付寶異步回調返回:請求參數爲空!");
return;
}
if(StringUtil.isEmpty(busiTypeCode)){
logger.info("支付寶異步回調返回:業務參數busiTypeCode爲空!");
return;
}
String callbackParam = "";
for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
String name = iter.next();
String[] values = requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
}
// 亂碼解決,這段代碼在出現亂碼時使用。若是mysign和sign不相等也能夠使用這段代碼轉化
params.put(name, valueStr);
callbackParam += ";"+name + ":" +valueStr;
}
logger.info("支付寶異步回調:" + callbackParam);
// 獲取支付寶的通知返回參數,可參考技術文檔中頁面跳轉同步通知參數列表(如下僅供參考)//
// 商戶訂單號
String orderNo = request.getParameter("out_order_no");
if(StringUtil.isEmpty(orderNo)){
orderNo = request.getParameter("out_trade_no");
}
//goloCars業務訂單號: 車輛訂單編號
if(orderNo.length() > 30){
orderNo = orderNo.substring(0, orderNo.length() - 13);
}
// 交易狀態
String status = request.getParameter("status");
// 交易流水號
String tradeNo = request.getParameter("trade_no");
// 交易金額
String tradeAmount = request.getParameter("amount");
// 預受權用戶在支付寶的uid--凍結轉支付必傳參數
String payUserId = request.getParameter("payer_user_id");
//插入water表流水做爲回調修改狀態基礎
//流水錶中添加訂單記錄: 支付寶預受權
BaseMapEntity purseWaterParams = new BaseMapEntity();
Date currentDate = new Date();
// 獲取支付寶的通知返回參數,可參考技術文檔中頁面跳轉同步通知參數列表(以上僅供參考)//
String publicKey = ConfigUtil.getSettings("alipay_public_key");
String charset = ConfigUtil.getSettings("charset");
String signType = ConfigUtil.getSettings("sign_type");
boolean signVerified = AlipaySignature.rsaCheckV1(params, publicKey, charset, signType);
purseWaterParams.put("state",1);//交易狀態(1.交易中,2.已到帳)
if (signVerified) {
if ("SUCCESS".equals(status)) {
purseWaterParams.put("state",2);//交易狀態(1.交易中,2.已到帳)
} else {
}
out.println("success"); // 請不要修改或刪除
} else {
// 驗證失敗
logger.error("支付寶異步回調失敗:驗證失敗");
out.println("fail");
}
//獲取訂單信息
BaseMapEntity orderParamMap = new BaseMapEntity();
orderParamMap.put("orderNo",orderNo);
BaseMapEntity vehicleOrderMap = vehicleOrderDao.queryVehicleOrderInfo(orderParamMap);
String userAlipayAccount = null;
if(null != vehicleOrderMap){
String userId = vehicleOrderMap.getString("userId");//租客id
purseWaterParams.put("userId",userId);//APP交易用戶ID
if(!StringUtil.isEmpty(userId)){
User user = userDao.selectByPrimaryKey(Integer.parseInt(userId));
if(user!=null){
userAlipayAccount = user.getAlipayAccount();//交易發起帳號
}
}
}
AlipayBusiTypeEnum busiTypeEnum = AlipayBusiTypeEnum.valueOf(busiTypeCode);
String busiTypeName = busiTypeEnum.getBusiTypeName();
purseWaterParams.put("orderNo",orderNo);//平臺訂單號
purseWaterParams.put("depositTime",currentDate);//交易申請時間
purseWaterParams.put("tradeAmount",tradeAmount);//交易金額(元)
purseWaterParams.put("payUserId", payUserId); //預受權用戶在支付寶的userId
purseWaterParams.put("waterRemark", busiTypeEnum.getBusiTypeDesc()); //業務類型描述busiTypeDesc
if("ZF".equals(busiTypeName)){//支付回調
}else if("YSQDJ".equals(busiTypeName)){//預受權凍結回調
// 支付寶資金受權訂單號
String authNo = request.getParameter("auth_no");
purseWaterParams.put("purseChannel",4);//交易方式(1.銀行卡 2.支付寶 3.微信 4.支付寶預受權凍結 5.支付寶預受權凍結轉支付 6.支付寶預受權解凍)
purseWaterParams.put("profitType",3);//交易類型(1.車主訂單收益 2.訂單退款 3.租客訂單支付 4.支付寶帳號驗證 5.運營人員訂單分紅 6.技師人員訂單分紅 7.二手車訂單支付)
purseWaterParams.put("tradeStartAccount",userAlipayAccount);//交易發起帳號
purseWaterParams.put("tradeReceiveAccount",ConfigUtil.getSettings("alipay_loginid"));//交易接收帳號
purseWaterParams.put("thirdTradeNo",authNo);//第三方的交易單號
try{
BaseMapEntity orderParams = new BaseMapEntity();
orderParams.put("orderNo",orderNo);//訂單編號
orderParams.put("payPrice",tradeAmount);//支付金額
orderParams.put("thirdTradeNo",authNo);//交易流水號
orderParams.put("payUserId", payUserId); //預受權用戶在支付寶的uid,凍結轉支付必傳
if("2".equals(purseWaterParams.getString("state"))){
orderAppService.updateOrderByAuthFreeze(orderParams);
}
}catch(Exception e){
logger.error(ExceptionUtil.getExceptionStr("支付寶預受權凍結回調接口失敗,緣由:", e));
}
}else if("YSQDJZZF".equals(busiTypeName)){//預受權凍結轉支付回調
purseWaterParams.put("purseChannel",5);//交易方式(1.銀行卡 2.支付寶 3.微信 4.支付寶預受權凍結 5.支付寶預受權凍結轉支付 6.支付寶預受權解凍)
purseWaterParams.put("profitType",3);//交易類型(1.車主訂單收益 2.訂單退款 3.租客訂單支付 4.支付寶帳號驗證 5.運營人員訂單分紅 6.技師人員訂單分紅 7.二手車訂單支付)
purseWaterParams.put("tradeStartAccount","支付寶");//交易發起帳號
purseWaterParams.put("tradeReceiveAccount",ConfigUtil.getSettings("alipay_loginid"));//交易接收帳號
purseWaterParams.put("thirdTradeNo",tradeNo);//第三方的交易單號
}else if("YSQJD".equals(busiTypeName)){//預受權解凍回調
purseWaterParams.put("purseChannel",6);//交易方式(1.銀行卡 2.支付寶 3.微信 4.支付寶預受權凍結 5.支付寶預受權凍結轉支付 6.支付寶預受權解凍)
purseWaterParams.put("profitType",3);//交易類型(1.車主訂單收益 2.訂單退款 3.租客訂單支付 4.支付寶帳號驗證 5.運營人員訂單分紅 6.技師人員訂單分紅 7.二手車訂單支付)
purseWaterParams.put("tradeStartAccount","支付寶");//交易發起帳號
purseWaterParams.put("tradeReceiveAccount",ConfigUtil.getSettings("alipay_loginid"));//交易接收帳號
purseWaterParams.put("thirdTradeNo",tradeNo);//第三方的交易單號
}else if("ZFTK".equals(busiTypeName)){//支付退款回調
purseWaterParams.put("purseChannel",2);//交易方式(1.銀行卡 2.支付寶 3.微信 4.支付寶預受權凍結 5.支付寶預受權凍結轉支付 6.支付寶預受權解凍)
purseWaterParams.put("profitType",2);//交易類型(1.車主訂單收益 2.訂單退款 3.租客訂單支付 4.支付寶帳號驗證 5.運營人員訂單分紅 6.技師人員訂單分紅 7.二手車訂單支付)
purseWaterParams.put("tradeStartAccount",ConfigUtil.getSettings("alipay_loginid"));//交易發起帳號
purseWaterParams.put("tradeReceiveAccount",userAlipayAccount);//交易接收帳號
purseWaterParams.put("thirdTradeNo",tradeNo);//第三方的交易單號
}else if("YSQTKJD".equals(busiTypeName)){//退款解凍回調
purseWaterParams.put("purseChannel",6);//交易方式(1.銀行卡 2.支付寶 3.微信 4.支付寶預受權凍結 5.支付寶預受權凍結轉支付 6.支付寶預受權解凍)
purseWaterParams.put("profitType",2);//交易類型(1.車主訂單收益 2.訂單退款 3.租客訂單支付 4.支付寶帳號驗證 5.運營人員訂單分紅 6.技師人員訂單分紅 7.二手車訂單支付)
purseWaterParams.put("tradeStartAccount","支付寶");//交易發起帳號
purseWaterParams.put("tradeReceiveAccount",userAlipayAccount);//交易接收帳號
purseWaterParams.put("thirdTradeNo",tradeNo);//第三方的交易單號
}
vehicleOrderDao.insertPurseWater(purseWaterParams);
}catch (Exception e){
logger.error(ExceptionUtil.getExceptionStr("支付寶異步回調接口失敗,緣由:", e));
}
logger.info("支付寶異步回調結束"); }