|  | @@ -0,0 +1,121 @@
 | 
	
		
			
				|  |  | +package cn.newfeifan.mall.module.pay.service.fuyouorder;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.dal.dataobject.order.PayOrderDO;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.fuiou.reqvo.SubmitOrderRequestVO;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.fuiou.respVO.FuYouPayOrderSubmitRespVO;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.fuiou.respVO.FuYouPaymentResponseVO;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.service.order.PayOrderService;
 | 
	
		
			
				|  |  | +import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.fuiou.util.DateUtils;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.fuiou.util.FuiouHttpPoster;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.pay.fuiou.util.MD5;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | +import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import org.springframework.validation.annotation.Validated;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.module.pay.enums.DictTypeConstants.*;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.module.pay.enums.ErrorCodeConstants.SUBMIT_ORDER_ERROR;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +@Validated
 | 
	
		
			
				|  |  | +@Slf4j
 | 
	
		
			
				|  |  | +public class FiYouPayOrderServiceImpl implements FuYouPayOrderService {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Value("${wx.mp.app-id}")
 | 
	
		
			
				|  |  | +    private String appid;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private PayOrderService payOrderService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public String submitOrder(SubmitOrderRequestVO requestVO) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 1.1 获得 PayOrderDO ,并校验其是否存在
 | 
	
		
			
				|  |  | +        PayOrderDO payOrder = payOrderService.validateOrderCanSubmit(requestVO.getId());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        FuiouHttpPoster http = new FuiouHttpPoster();
 | 
	
		
			
				|  |  | +        http.setCharset("utf-8");
 | 
	
		
			
				|  |  | +        http.setUrl("https://aipay.fuioupay.com/aggregatePay/wxPreCreate");
 | 
	
		
			
				|  |  | +        requestVO.getReq().setTerm_id("88888888");
 | 
	
		
			
				|  |  | +        requestVO.getReq().setTerm_ip("192.168.8.8");
 | 
	
		
			
				|  |  | +        requestVO.getReq().setRandom_str(DateUtils.getCurrentDate("yyyyMMddHHmmss")
 | 
	
		
			
				|  |  | +                + "568974");
 | 
	
		
			
				|  |  | +        requestVO.getReq().setMchnt_cd(mchnt_cd);
 | 
	
		
			
				|  |  | +//        requestVO.getReq().setTrade_type("JSAPI");
 | 
	
		
			
				|  |  | +//      req.setOpenid("oDax96l0bZdXqRQ2uVfn_2LV-DxM");//微信支付此字段必填
 | 
	
		
			
				|  |  | +//		req.setSub_openid("221122121");//支付宝支付此字段必填
 | 
	
		
			
				|  |  | +        requestVO.getReq().setOrder_amt(String.valueOf(payOrder.getPrice() / 100));
 | 
	
		
			
				|  |  | +        requestVO.getReq().setGoods_des(payOrder.getBody());
 | 
	
		
			
				|  |  | +//        requestVO.getReq().setOpenid("osMm86Ggu3iLCkdCO2j4Zan-fHOQ");
 | 
	
		
			
				|  |  | +//        requestVO.getReq().setSub_openid("osMm86Ggu3iLCkdCO2j4Zan-fHOQ");
 | 
	
		
			
				|  |  | +//        requestVO.getReq().setSub_appid("wxe133514440a8829d");
 | 
	
		
			
				|  |  | +        requestVO.getReq().setSub_appid(appid);
 | 
	
		
			
				|  |  | +        requestVO.getReq().setMchnt_order_no(payOrder.getPayOrderNo());//不能重复
 | 
	
		
			
				|  |  | +        requestVO.getReq().setTxn_begin_ts(DateUtils.getCurrentDate("yyyyMMddHHmmss"));
 | 
	
		
			
				|  |  | +        requestVO.getReq().setNotify_url("https://zxpt.newfeifan.cn/fuYou/pay/order/notify");
 | 
	
		
			
				|  |  | +        requestVO.getReq().setVersion("1.0");
 | 
	
		
			
				|  |  | +        StringBuilder sb = new StringBuilder();
 | 
	
		
			
				|  |  | +        sb.append(requestVO.getReq().getMchnt_cd().trim()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getTrade_type().trim()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getOrder_amt().trim()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getMchnt_order_no().trim()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getTxn_begin_ts()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getGoods_des()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getTerm_id()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getTerm_ip()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getNotify_url()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getRandom_str()).append("|")
 | 
	
		
			
				|  |  | +                .append(requestVO.getReq().getVersion()).append("|")
 | 
	
		
			
				|  |  | +                .append(privateKey);
 | 
	
		
			
				|  |  | +        requestVO.getReq().setSign(MD5.MD5Encode(sb.toString()));
 | 
	
		
			
				|  |  | +        String res = null;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            res = http.newPost(JSON.toJSONString(requestVO.getReq()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // 解析返回结果,获取参数
 | 
	
		
			
				|  |  | +            ObjectMapper mapper = new ObjectMapper();
 | 
	
		
			
				|  |  | +            FuYouPaymentResponseVO resp = mapper.readValue(res, FuYouPaymentResponseVO.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if(!"000000".equals(resp.getResult_code())){
 | 
	
		
			
				|  |  | +                throw exception(SUBMIT_ORDER_ERROR);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            FuYouPayOrderSubmitRespVO vo = FuYouPayOrderSubmitRespVO.builder()
 | 
	
		
			
				|  |  | +                    .appId(resp.getSdk_appid())
 | 
	
		
			
				|  |  | +                    .timeStamp(resp.getSdk_timestamp())
 | 
	
		
			
				|  |  | +                    .nonceStr(resp.getRandom_str())
 | 
	
		
			
				|  |  | +                    .sdk_package(resp.getSdk_package())
 | 
	
		
			
				|  |  | +                    .signType(resp.getSdk_signtype())
 | 
	
		
			
				|  |  | +                    .paySign(resp.getSdk_paysign())
 | 
	
		
			
				|  |  | +                    .build();
 | 
	
		
			
				|  |  | +            return JSON.toJSONString(vo);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            throw exception(SUBMIT_ORDER_ERROR);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void afterSale(Long afterSaleId) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 生成随机字符串
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private static String generateRandomString(int length) {
 | 
	
		
			
				|  |  | +        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 | 
	
		
			
				|  |  | +        StringBuilder sb = new StringBuilder();
 | 
	
		
			
				|  |  | +        for (int i = 0; i < length; i++) {
 | 
	
		
			
				|  |  | +            int index = (int) (characters.length() * Math.random());
 | 
	
		
			
				|  |  | +            sb.append(characters.charAt(index));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return sb.toString();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |