Commit a9a5e089 authored by 周健威's avatar 周健威

修改代码

parent 18ebbb50
......@@ -88,8 +88,8 @@ public interface ThirdFeign {
/*************************************支付***************************************/
@PostMapping("/pay/app/unauth/transfer_account")
ObjectRestResponse<String> transferAccount(@RequestBody FundPayVo fundPayVo);
// @PostMapping("/pay/app/unauth/transfer_account")
// ObjectRestResponse<String> transferAccount(@RequestBody FundPayVo fundPayVo);
@GetMapping("/info/app/unauth/getAliPayUserInfo")
public ObjectRestResponse<String> getAliPayUserInfo(@RequestParam(value = "code")String code);
......
......@@ -51,30 +51,30 @@ public class WXSuppToUserPay {
private String spbill_create_ip;//Ip地址
private String key;
public static Map<String,String> WeiXinTiXian(String openid,String partnerTradeNo,String check_name,String amount,String desc,String spbill_create_ip)
{
WXSuppToUserPay prePay = new WXSuppToUserPay();
prePay.setMch_appid(SystemConfig.APP_ID);
prePay.setMchid(SystemConfig.APP_PARTNER);
prePay.setNonce_str( OrderUtil.CreateNoncestr());
prePay.setPartner_trade_no(partnerTradeNo);
prePay.setOpenid(openid);
prePay.setCheck_name(check_name);
prePay.setAmount(amount);
prePay.setDesc(desc);
prePay.setSpbill_create_ip(spbill_create_ip);
String result =postXML(suppTouser,prePay.getXMLTuiKuan());
result = result.replaceAll("<![CDATA[|]]>", "").replaceAll("支付成功", "pay sucess");
Map<String, String> map = null;
try {
map = XMLUtil.doXMLParse(result);
} catch (JDOMException e) {
throw new BaseException("微信转账参数xml解析错误",e);
} catch (IOException e) {
throw new BaseException("微信转账参数xml解析读写IO异常",e);
}
return map;
}
// public static Map<String,String> WeiXinTiXian(String openid,String partnerTradeNo,String check_name,String amount,String desc,String spbill_create_ip)
// {
// WXSuppToUserPay prePay = new WXSuppToUserPay();
// prePay.setMch_appid(SystemConfig.APP_ID);
// prePay.setMchid(SystemConfig.APP_PARTNER);
// prePay.setNonce_str( OrderUtil.CreateNoncestr());
// prePay.setPartner_trade_no(partnerTradeNo);
// prePay.setOpenid(openid);
// prePay.setCheck_name(check_name);
// prePay.setAmount(amount);
// prePay.setDesc(desc);
// prePay.setSpbill_create_ip(spbill_create_ip);
// String result =postXML(suppTouser,prePay.getXMLTuiKuan());
// result = result.replaceAll("<![CDATA[|]]>", "").replaceAll("支付成功", "pay sucess");
// Map<String, String> map = null;
// try {
// map = XMLUtil.doXMLParse(result);
// } catch (JDOMException e) {
// throw new BaseException("微信转账参数xml解析错误",e);
// } catch (IOException e) {
// throw new BaseException("微信转账参数xml解析读写IO异常",e);
// }
// return map;
// }
public static String postXML(String uri, String xml) {
CloseableHttpClient httpclient = null;
try {
......@@ -183,39 +183,39 @@ public class WXSuppToUserPay {
public String getXMLTuiKuan(){
TreeMap<String, String> treeMap = new TreeMap<String, String>();
treeMap.put("mch_appid", this.mch_appid);
treeMap.put("mchid", this.mchid);
treeMap.put("nonce_str", this.nonce_str);
treeMap.put("partner_trade_no", this.partner_trade_no);
treeMap.put("openid", this.openid);
treeMap.put("check_name", this.check_name);
//treeMap.put("re_user_name", this.re_user_name);
treeMap.put("amount", this.amount);
treeMap.put("desc", this.desc);
treeMap.put("spbill_create_ip", this.spbill_create_ip);
//treeMap.put("key", this.key);
//treeMap.put("sign", this.sign);
StringBuilder sb = new StringBuilder();
for (String key : treeMap.keySet()) {
sb.append(key).append("=").append(treeMap.get(key)).append("&");
}
sb.append("key=" + SystemConfig.WINXIN_PARTNER_KEY);
sign = MD5Util.MD5Encode(sb.toString(), "utf-8").toUpperCase();
treeMap.put("sign", sign);
StringBuilder xml = new StringBuilder();
xml.append("<xml>\n");
for (Map.Entry<String, String> entry : treeMap.entrySet()) {
if ("body".equals(entry.getKey()) || "sign".equals(entry.getKey())) {
xml.append("<" + entry.getKey() + "><![CDATA[").append(entry.getValue()).append("]]></" + entry.getKey() + ">\n");
} else {
xml.append("<" + entry.getKey() + ">").append(entry.getValue()).append("</" + entry.getKey() + ">\n");
}
}
xml.append("</xml>");
return xml.toString();
}
// public String getXMLTuiKuan(){
// TreeMap<String, String> treeMap = new TreeMap<String, String>();
// treeMap.put("mch_appid", this.mch_appid);
// treeMap.put("mchid", this.mchid);
// treeMap.put("nonce_str", this.nonce_str);
// treeMap.put("partner_trade_no", this.partner_trade_no);
// treeMap.put("openid", this.openid);
// treeMap.put("check_name", this.check_name);
// //treeMap.put("re_user_name", this.re_user_name);
// treeMap.put("amount", this.amount);
// treeMap.put("desc", this.desc);
// treeMap.put("spbill_create_ip", this.spbill_create_ip);
// //treeMap.put("key", this.key);
// //treeMap.put("sign", this.sign);
// StringBuilder sb = new StringBuilder();
// for (String key : treeMap.keySet()) {
// sb.append(key).append("=").append(treeMap.get(key)).append("&");
// }
// sb.append("key=" + SystemConfig.WINXIN_PARTNER_KEY);
// sign = MD5Util.MD5Encode(sb.toString(), "utf-8").toUpperCase();
// treeMap.put("sign", sign);
// StringBuilder xml = new StringBuilder();
// xml.append("<xml>\n");
// for (Map.Entry<String, String> entry : treeMap.entrySet()) {
// if ("body".equals(entry.getKey()) || "sign".equals(entry.getKey())) {
// xml.append("<" + entry.getKey() + "><![CDATA[").append(entry.getValue()).append("]]></" + entry.getKey() + ">\n");
// } else {
// xml.append("<" + entry.getKey() + ">").append(entry.getValue()).append("</" + entry.getKey() + ">\n");
// }
// }
// xml.append("</xml>");
// return xml.toString();
// }
public String getMch_appid() {
......
......@@ -498,27 +498,27 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
}
}
/**
* 转账功能 微信 | 支付宝
*
* @param fundPayVo
* @return
* @throws Exception
*/
public String fundTrans(FundPayVo fundPayVo) throws BaseException {
String cono = OrderUtil.GetOrderNumber("");
fundPayVo.setOutBizNo(cono);
if (fundPayVo.getType() == PayWay.WX_PAY.getCode()) {
//微信
fundPayVo.setCheckName("NO_CHECK");
return wxpayfundTrans(fundPayVo);
}
if (fundPayVo.getType() == PayWay.ALI_PAY.getCode()) {
//支付宝
return alipayfundTrans(getAlipayClient(), fundPayVo);
}
throw new BaseException("提现方式不对");
}
// /**
// * 转账功能 微信 | 支付宝
// *
// * @param fundPayVo
// * @return
// * @throws Exception
// */
// public String fundTrans(FundPayVo fundPayVo) throws BaseException {
// String cono = OrderUtil.GetOrderNumber("");
// fundPayVo.setOutBizNo(cono);
// if (fundPayVo.getType() == PayWay.WX_PAY.getCode()) {
// //微信
// fundPayVo.setCheckName("NO_CHECK");
// return wxpayfundTrans(fundPayVo);
// }
// if (fundPayVo.getType() == PayWay.ALI_PAY.getCode()) {
// //支付宝
// return alipayfundTrans(getAlipayClient(), fundPayVo);
// }
// throw new BaseException("提现方式不对");
// }
/**
* 支付宝转账功能 单笔最小转账0.1 最大小数点位数前支持13位,实际限额和签约一致
......@@ -549,13 +549,13 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
}
}
public String wxpayfundTrans(FundPayVo fundPayVo) {
Map<String, String> map = WXSuppToUserPay.WeiXinTiXian(fundPayVo.getPayeeAccount(), fundPayVo.getOutBizNo(), fundPayVo.getCheckName(), fundPayVo.getAmount(), fundPayVo.getRemark(), fundPayVo.getCreatIp());
if (SUCCESS.equals(map.get(WxResponseProperties.RETURN_CODE)) && SUCCESS.equals(map.get(WxResponseProperties.RESULT_CODE))) {
return map.get(WxResponseProperties.PARTNER_TRADE_NO);
}
throw new BaseException(map.get(WxResponseProperties.ERR_CODE_DES), map.get(WxResponseProperties.ERROR_CODE));
}
// public String wxpayfundTrans(FundPayVo fundPayVo) {
// Map<String, String> map = WXSuppToUserPay.WeiXinTiXian(fundPayVo.getPayeeAccount(), fundPayVo.getOutBizNo(), fundPayVo.getCheckName(), fundPayVo.getAmount(), fundPayVo.getRemark(), fundPayVo.getCreatIp());
// if (SUCCESS.equals(map.get(WxResponseProperties.RETURN_CODE)) && SUCCESS.equals(map.get(WxResponseProperties.RESULT_CODE))) {
// return map.get(WxResponseProperties.PARTNER_TRADE_NO);
// }
// throw new BaseException(map.get(WxResponseProperties.ERR_CODE_DES), map.get(WxResponseProperties.ERROR_CODE));
// }
/**
......
......@@ -121,17 +121,17 @@ public class OrderPayController extends BaseController<OrderPayBiz,OrderPay> {
return baseBiz.updateStatus(orderPay);
}
@PostMapping("/app/unauth/transfer_account")
@IgnoreUserToken
public ObjectRestResponse<String> transferAccount(@RequestBody FundPayVo fundPayVo){
try {
String pay_no = baseBiz.fundTrans(fundPayVo);
return ObjectRestResponse.succ(pay_no);
}catch (Exception ex){
return ObjectRestResponse.createFailedResult(400,ex.getMessage());
}
}
// @PostMapping("/app/unauth/transfer_account")
// @IgnoreUserToken
// public ObjectRestResponse<String> transferAccount(@RequestBody FundPayVo fundPayVo){
// try {
// String pay_no = baseBiz.fundTrans(fundPayVo);
// return ObjectRestResponse.succ(pay_no);
// }catch (Exception ex){
// return ObjectRestResponse.createFailedResult(400,ex.getMessage());
// }
//
// }
}
\ No newline at end of file
package com.upyuns.platform.rs.universal.handler;
import com.alibaba.fastjson.JSON;
import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.upyuns.platform.rs.universal.biz.OrderPayBiz;
import com.upyuns.platform.rs.universal.constant.AliPayErrorEnum;
import com.upyuns.platform.rs.universal.constant.PayWay;
import com.upyuns.platform.rs.universal.constant.WxPayErrorEnum;
import com.upyuns.platform.rs.universal.vo.FundPayVo;
import com.upyuns.platform.rs.universal.constant.AliNeedPayErrorEnum;
import com.upyuns.platform.rs.universal.constant.WxNeedPayErrorEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;
import com.rabbitmq.client.Channel;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
//import static com.upyuns.platform.rs.universal.config.RabbitUniversalConfig.WITH_DRAW_QUEUE;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/10/17 17:20
*/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class WithDrawMqHandler implements InitializingBean {
private List<String> needPayErrorCodes;
private List<String> wxPayErrorCodes;
private List<String> aliPayErrorCodes;
private final UserFeign userFeign;
private final OrderPayBiz orderPayBiz;
@Resource(name = "redisTemplate")
private ValueOperations valueOperations;
private final RedisTemplate<String, String> redisTemplate;
private static final int MAX_RETRY = 3;
private static final String DEFAULT_ERROR_MSG = "当前操作有误,如有疑问请咨询客服";
/**
* 钱包提现
*
* @param
*/
//@RabbitListener(queues = WITH_DRAW_QUEUE)
public void integralHandler(Message message, @Headers Map<String, Object> headers, Channel channel) {
FundPayVo fundPayVo = null;
String pay_way = "";
Integer cathType = null;
String orderNo = "";
try {
String msg = new String(message.getBody(), "UTF-8");
fundPayVo = JSON.parseObject(msg, FundPayVo.class);
cathType = fundPayVo.getType();
pay_way = fundPayVo.getType() == PayWay.WX_PAY.getCode() ?
PayWay.WX_PAY.getDesc() : fundPayVo.getType() == PayWay.ALI_PAY.getCode() ?
PayWay.ALI_PAY.getDesc() : fundPayVo.getType() == PayWay.BANK.getCode() ?
PayWay.BANK.getDesc() : "";
String cono = orderPayBiz.fundTrans(fundPayVo);
orderNo = fundPayVo.getOrderNo();
log.info("提现成功:【商户订单号:{}】-->【{}】", cono,msg);
userFeign.withDrawprocess(fundPayVo.getOrderNo(), cono, "", true,"");
Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
// 手动签收
basicAck(channel, deliveryTag, false, pay_way);
} catch (UnsupportedEncodingException e) {
basicNack(channel, message.getMessageProperties().getDeliveryTag(), false, false, pay_way);
userFeign.withDrawprocess(fundPayVo.getOrderNo(), "",DEFAULT_ERROR_MSG, false,e.getMessage());
String reason = String.format("%s%s%s", pay_way, "转账失败", "[不支持的编码:UTF-8]");
log.info("{}:【{}】", reason, e);
} catch (BaseException e) {
//错误码
String subCode = e.getSubCode();
//再次发消息
if (needPayErrorCodes.contains(subCode)) {
Long count = valueOperations.increment(orderNo);
if (count <= MAX_RETRY) {
//重新把消息放回队列
basicNack(channel, message.getMessageProperties().getDeliveryTag(), false, true, pay_way);
try {
channel.basicRecover();
}catch (IOException ex){
}
return;
}
redisTemplate.delete(orderNo);
}
String msg = "";
if (wxPayErrorCodes.contains(subCode) && cathType != null && cathType == PayWay.WX_PAY.getCode()) {
msg = WxPayErrorEnum.valueOf(subCode).getSubReason();
}
if (aliPayErrorCodes.contains(subCode) && cathType != null && cathType == PayWay.ALI_PAY.getCode()) {
msg = AliPayErrorEnum.valueOf(subCode).getSubReason();
}
String reason = StringUtils.isEmpty(msg) ? DEFAULT_ERROR_MSG : msg;
userFeign.withDrawprocess(fundPayVo.getOrderNo(), "",reason, false,e.getMessage());
//放弃此消息
basicNack(channel, message.getMessageProperties().getDeliveryTag(), false, false, pay_way);
}
}
private void basicAck(Channel channel, long deliveryTag, boolean multiple, String pay_way) {
try {
channel.basicAck(deliveryTag, multiple);
} catch (IOException ex) {
log.info("{}提现转账消息签收失败:【{}】", pay_way, ex);
}
}
private void basicNack(Channel channel, long deliveryTag, boolean multiple, boolean requeue, String pay_way) {
try {
channel.basicNack(deliveryTag, multiple, requeue);
} catch (IOException ex) {
log.info("{}提现转账消息{}失败:【{}】", pay_way, requeue ? "重回队列" : "丢弃", ex);
}
}
@Override
public void afterPropertiesSet() throws Exception {
needPayErrorCodes = Stream.concat(EnumSet.allOf(WxNeedPayErrorEnum.class).stream().map(WxNeedPayErrorEnum::name), EnumSet.allOf(AliNeedPayErrorEnum.class).stream().map(AliNeedPayErrorEnum::name))
.distinct()
.collect(Collectors.toList());
wxPayErrorCodes = EnumSet.allOf(WxPayErrorEnum.class).stream().map(WxPayErrorEnum::name).collect(Collectors.toList());
aliPayErrorCodes = EnumSet.allOf(AliPayErrorEnum.class).stream().map(AliPayErrorEnum::name).collect(Collectors.toList());
}
}
//package com.upyuns.platform.rs.universal.handler;
//
//import com.alibaba.fastjson.JSON;
//import com.github.wxiaoqi.security.admin.feign.UserFeign;
//import com.github.wxiaoqi.security.common.exception.BaseException;
//import com.upyuns.platform.rs.universal.biz.OrderPayBiz;
//import com.upyuns.platform.rs.universal.constant.AliPayErrorEnum;
//import com.upyuns.platform.rs.universal.constant.PayWay;
//import com.upyuns.platform.rs.universal.constant.WxPayErrorEnum;
//import com.upyuns.platform.rs.universal.vo.FundPayVo;
//import com.upyuns.platform.rs.universal.constant.AliNeedPayErrorEnum;
//import com.upyuns.platform.rs.universal.constant.WxNeedPayErrorEnum;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.ValueOperations;
//import org.springframework.messaging.handler.annotation.Headers;
//import org.springframework.stereotype.Component;
//import com.rabbitmq.client.Channel;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.util.EnumSet;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
////import static com.upyuns.platform.rs.universal.config.RabbitUniversalConfig.WITH_DRAW_QUEUE;
//
///**
// * @author libin
// * @version 1.0
// * @description
// * @data 2019/10/17 17:20
// */
//@Component
//@RequiredArgsConstructor(onConstructor = @__(@Autowired))
//@Slf4j
//public class WithDrawMqHandler implements InitializingBean {
// private List<String> needPayErrorCodes;
// private List<String> wxPayErrorCodes;
// private List<String> aliPayErrorCodes;
// private final UserFeign userFeign;
// private final OrderPayBiz orderPayBiz;
// @Resource(name = "redisTemplate")
// private ValueOperations valueOperations;
// private final RedisTemplate<String, String> redisTemplate;
// private static final int MAX_RETRY = 3;
// private static final String DEFAULT_ERROR_MSG = "当前操作有误,如有疑问请咨询客服";
//
// /**
// * 钱包提现
// *
// * @param
// */
// //@RabbitListener(queues = WITH_DRAW_QUEUE)
// public void integralHandler(Message message, @Headers Map<String, Object> headers, Channel channel) {
// FundPayVo fundPayVo = null;
// String pay_way = "";
// Integer cathType = null;
// String orderNo = "";
// try {
// String msg = new String(message.getBody(), "UTF-8");
// fundPayVo = JSON.parseObject(msg, FundPayVo.class);
// cathType = fundPayVo.getType();
// pay_way = fundPayVo.getType() == PayWay.WX_PAY.getCode() ?
// PayWay.WX_PAY.getDesc() : fundPayVo.getType() == PayWay.ALI_PAY.getCode() ?
// PayWay.ALI_PAY.getDesc() : fundPayVo.getType() == PayWay.BANK.getCode() ?
// PayWay.BANK.getDesc() : "";
// String cono = orderPayBiz.fundTrans(fundPayVo);
// orderNo = fundPayVo.getOrderNo();
// log.info("提现成功:【商户订单号:{}】-->【{}】", cono,msg);
// userFeign.withDrawprocess(fundPayVo.getOrderNo(), cono, "", true,"");
// Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
// // 手动签收
// basicAck(channel, deliveryTag, false, pay_way);
// } catch (UnsupportedEncodingException e) {
// basicNack(channel, message.getMessageProperties().getDeliveryTag(), false, false, pay_way);
// userFeign.withDrawprocess(fundPayVo.getOrderNo(), "",DEFAULT_ERROR_MSG, false,e.getMessage());
// String reason = String.format("%s%s%s", pay_way, "转账失败", "[不支持的编码:UTF-8]");
// log.info("{}:【{}】", reason, e);
// } catch (BaseException e) {
// //错误码
// String subCode = e.getSubCode();
// //再次发消息
// if (needPayErrorCodes.contains(subCode)) {
// Long count = valueOperations.increment(orderNo);
// if (count <= MAX_RETRY) {
// //重新把消息放回队列
// basicNack(channel, message.getMessageProperties().getDeliveryTag(), false, true, pay_way);
// try {
// channel.basicRecover();
// }catch (IOException ex){
//
// }
// return;
// }
// redisTemplate.delete(orderNo);
// }
// String msg = "";
// if (wxPayErrorCodes.contains(subCode) && cathType != null && cathType == PayWay.WX_PAY.getCode()) {
// msg = WxPayErrorEnum.valueOf(subCode).getSubReason();
// }
// if (aliPayErrorCodes.contains(subCode) && cathType != null && cathType == PayWay.ALI_PAY.getCode()) {
// msg = AliPayErrorEnum.valueOf(subCode).getSubReason();
// }
// String reason = StringUtils.isEmpty(msg) ? DEFAULT_ERROR_MSG : msg;
// userFeign.withDrawprocess(fundPayVo.getOrderNo(), "",reason, false,e.getMessage());
// //放弃此消息
// basicNack(channel, message.getMessageProperties().getDeliveryTag(), false, false, pay_way);
// }
// }
//
// private void basicAck(Channel channel, long deliveryTag, boolean multiple, String pay_way) {
// try {
// channel.basicAck(deliveryTag, multiple);
// } catch (IOException ex) {
// log.info("{}提现转账消息签收失败:【{}】", pay_way, ex);
// }
// }
//
// private void basicNack(Channel channel, long deliveryTag, boolean multiple, boolean requeue, String pay_way) {
// try {
// channel.basicNack(deliveryTag, multiple, requeue);
// } catch (IOException ex) {
// log.info("{}提现转账消息{}失败:【{}】", pay_way, requeue ? "重回队列" : "丢弃", ex);
// }
// }
//
// @Override
// public void afterPropertiesSet() throws Exception {
// needPayErrorCodes = Stream.concat(EnumSet.allOf(WxNeedPayErrorEnum.class).stream().map(WxNeedPayErrorEnum::name), EnumSet.allOf(AliNeedPayErrorEnum.class).stream().map(AliNeedPayErrorEnum::name))
// .distinct()
// .collect(Collectors.toList());
// wxPayErrorCodes = EnumSet.allOf(WxPayErrorEnum.class).stream().map(WxPayErrorEnum::name).collect(Collectors.toList());
// aliPayErrorCodes = EnumSet.allOf(AliPayErrorEnum.class).stream().map(AliPayErrorEnum::name).collect(Collectors.toList());
// }
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment