| | |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.io.IOException; |
| | |
| | | import java.util.SortedMap; |
| | | import java.util.TreeMap; |
| | | |
| | | @Service("toPaySMOImpl") |
| | | public class ToPaySMOImpl extends AppAbstractComponentSMO implements IToPaySMO { |
| | | private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class); |
| | | |
| | |
| | | |
| | | JSONObject userResult = JSONObject.parseObject(responseEntity.getBody().toString()); |
| | | int total = userResult.getIntValue("total"); |
| | | if(total < 1){ |
| | | if (total < 1) { |
| | | //未查询到用户信息 |
| | | throw new IllegalArgumentException("未查询微信用户"); |
| | | } |
| | |
| | | resultMap.put("package", "prepay_id=" + resMap.get("prepay_id")); |
| | | resultMap.put("signType", "MD5"); |
| | | resultMap.put("sign", PayUtil.createSign(resultMap, wechatAuthProperties.getKey())); |
| | | resultMap.put("returnCode", "SUCCESS"); |
| | | resultMap.put("returnMsg", "OK"); |
| | | resultMap.put("code", "0"); |
| | | resultMap.put("msg", "下单成功"); |
| | | logger.info("【小程序支付】统一下单成功,返回参数:" + resultMap); |
| | | } else { |
| | | resultMap.put("returnCode", resMap.get("return_code")); |
| | | resultMap.put("returnMsg", resMap.get("return_msg")); |
| | | resultMap.put("code", resMap.get("return_code")); |
| | | resultMap.put("msg", resMap.get("return_msg")); |
| | | logger.info("【小程序支付】统一下单失败,失败原因:" + resMap.get("return_msg")); |
| | | } |
| | | return resultMap; |
| | |
| | | paramMap.put("appid", wechatAuthProperties.getAppId()); |
| | | paramMap.put("mch_id", wechatAuthProperties.getMchId()); |
| | | paramMap.put("nonce_str", PayUtil.makeUUID(32)); |
| | | paramMap.put("body", ""); |
| | | paramMap.put("body", "HC智慧家园-停车费"); |
| | | paramMap.put("out_trade_no", orderNum); |
| | | paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount)); |
| | | paramMap.put("spbill_create_ip", PayUtil.getLocalIp()); |
| | |
| | | //转换为xml |
| | | String xmlData = PayUtil.mapToXml(paramMap); |
| | | |
| | | logger.debug("调用支付统一下单接口" + xmlData); |
| | | |
| | | ResponseEntity<String> responseEntity = restTemplate.postForEntity( |
| | | wechatAuthProperties.getWxPayUnifiedOrder(), xmlData, String.class); |
| | | |
| | | logger.debug("统一下单返回"+responseEntity); |
| | | //请求微信后台,获取预支付ID |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | throw new IllegalArgumentException("支付失败" + responseEntity.getBody()); |