Controller接口层:
@RestController@RequestMapping(value = https://www.isolves.com/it/cxkf/ydd/xcx/2019-09-04/"/api/payment/")public class PaymentController { private static Logger logger = LoggerFactory.getLogger(PaymentController.class); @Autowired private PaymentService paymentService;/** * App支付接口 * 微信和支付宝统一下单入口 ** @param request * @return * @throws Exception */ @ResponseBody @RequestMapping(value="toPay", method=RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public JSONObject toPay(HttpServletRequest request) throws Exception { String requestStr = RequestStr.getRequestStr(request); if (StringUtils.isEmpty(requestStr)) { throw new ParamException(); } JSONObject jsonObj = JSONObject.parseobject(requestStr); if(StringUtils.isEmpty(jsonObj.getString("orderNo")) || StringUtils.isEmpty(jsonObj.getString("payAmount"))){ throw new ParamException(); } //验证订单是否存在 String orderNo = jsonObj.getString("orderNo"); double payAmount = jsonObj.getDouble("payAmount"); if(payAmount < 0.01){ return AjaxUtil.renderFailMsg("订单有误 , 请确认!"); } else { //微信支付 Map
文章插图
PaymentService实现类部分代码(微信App支付):
@Service(value = https://www.isolves.com/it/cxkf/ydd/xcx/2019-09-04/"paymentService")public class PaymentServiceImpl implements PaymentService {private static Logger LOGGER = LoggerFactory.getLogger(PaymentServiceImpl.class); @Value("${spring.profiles.active}") private String PROJECT_ENV; @Value("${hcc.pay.domain}") private String payDomain; @Autowired private PaymentRecordMapper paymentRecordMapper;@Override @Transactional(readOnly=false,rollbackFor={Exception.class}) public Map
/** * <p>微信支付统一下单</p> * * @param orderId 订单编号 * @param tradeType 支付类型 * @param payAmount 支付金额 * @param openid * @return * @throws Exception */ private Map<String,String> wxUnifieldOrder(String orderId, String tradeType, double payAmount, String openid) throws Exception{ //封装参数 SortedMap<String,String> paramMap = new TreeMap<String,String>(); String appid = PayConfig.WX_APP_ID; String mchid = PayConfig.WX_MCH_ID; if(PayConstant.WX_TRADE_TYPE_JSAPI.equals(tradeType)){ appid = PayConfig.XCX_APP_ID; mchid = PayConfig.XCX_MCH_ID; } paramMap.put("appid", appid); paramMap.put("mch_id", mchid); paramMap.put("nonce_str", PayUtils.makeUUID(32)); paramMap.put("body", BaseConstants.PLATFORM_COMPANY_NAME); paramMap.put("out_trade_no", orderId); paramMap.put("total_fee", PayUtils.moneyToIntegerStr(payAmount)); paramMap.put("spbill_create_ip", PayUtils.getLocalIp()); paramMap.put("notify_url", this.getNotifyUrl(PayConstant.PAY_TYPE_WX)); paramMap.put("trade_type", tradeType); if(PayConstant.WX_TRADE_TYPE_JSAPI.equals(tradeType)){ paramMap.put("openid",openid); } paramMap.put("sign", PayUtils.createSign(paramMap,PayConfig.WX_KEY)); //转换为xml String xmlData = https://www.isolves.com/it/cxkf/ydd/xcx/2019-09-04/PayUtils.mapToXml(paramMap); //请求微信后台 String resXml = HttpUtils.postData(PayConfig.WX_PAY_UNIFIED_ORDER, xmlData); LOGGER.info("【微信支付】 统一下单响应:n"+resXml); return PayUtils.xmlStrToMap(resXml); }
推荐阅读
- 微信公众号的推广渠道和方法
- 微信运动一万步相当于多远的距离?让医生为您详细分析下
- 支付宝注销再注册是新用户吗 支付宝注销账户
- 查一下!你的微信是否被举报过
- 揭秘分析:都知道微信占用大量空间,究竟是些什么东西呢?
- 微信,一个能快速定位好友信息的小技巧
- 这2个开关能让微信里的钱更安全,很多用户都这么做,你开启了吗
- 微信受限制支付不了怎样解决?
- 如何快速完整的备份和导出微信聊天记录
- 用微信赚钱的小心了,这些操作全都被禁止