2019独角兽企业重金招聘Python工程师标准>>>
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");
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;
}
public String getBusiTypeCode(){
return this.busiTypeCode;
}
public String getBusiTypeName(){
return this.busiTypeName;
}
public String getBusiTypeDesc(){
return this.busiTypeDesc;
}
}
4.
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));
}
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
Map
if (requestParams.size() == 0) {
logger.info("支付宝异步回调返回:请求参数为空!");
return;
}
if(StringUtil.isEmpty(busiTypeCode)){
logger.info("支付宝异步回调返回:业务参数busiTypeCode为空!");
return;
}
String callbackParam = "";
for (Iterator
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("支付宝异步回调结束");
}