//package com.zteits.pay.weixinpublic; // //import java.util.HashMap; //import java.util.Map; // //import org.apache.commons.lang3.StringUtils; //import com.alibaba.fastjson.JSONObject; // //import com.clouds.common.utils.WxConfigUtil; //import com.zteits.clouds.api.apibase.bean.BizResult; //import com.zteits.clouds.api.apibase.constants.ErrorType; //import com.zteits.clouds.api.dto.pay.TdBPayOrderDTO; //import com.zteits.clouds.api.dto.pay.TdBWxConfigDTO; //import com.zteits.pay.weixin.util.PaymentUtil; //import com.zteits.pay.weixinpublic.util.PaymentApi; //import com.zteits.pay.weixinpublic.util.TradeType; // //import org.eclipse.jetty.util.StringUtil; //import org.slf4j.Logger; //import org.slf4j.LoggerFactory; // ///** // * 微信公众号统一下单工具类.
// * // * Copyright: Copyright (c) 2017 zteits // * // * @ClassName: WeiXinPublicPayUtil.java // * @Description: // * @version: v1.0.0 // * @author: wangfs // * @date: 2017年9月4日 下午7:01:55 // * Modification History: // * Date Author Version Description // * ---------------------------------------------------------* // * 2017年9月4日 wangfs v1.0.0 创建 // */ // //public class WeiXinPublicPayUtil { // // private static final Logger logger = LoggerFactory.getLogger(WeiXinPublicPayUtil.class); // // /** // * 统一下单接口.
// * // * @param payOrderDTO // * @param openId // * @param body TODO // * @return // */ // public static BizResult unifiedOrder(TdBPayOrderDTO payOrderDTO, String openId, TdBWxConfigDTO configDTO, // String notifyUrl, String body) { // BizResult bizResult = new BizResult<>(); // Map params = new HashMap(); // // //封装参数 // params.put("appid", configDTO.getAppid()); // params.put("mch_id", configDTO.getMchid() + ""); // if(StringUtil.isNotBlank(body)) { // params.put("body", body); // }else { // params.put("body", "任你停公众号订单支付"); // } // params.put("out_trade_no", payOrderDTO.getPayOrderId()); // //支付金额 // params.put("total_fee", payOrderDTO.getOrderActFee() != null ? payOrderDTO.getOrderActFee().toString() : "0"); // // params.put("spbill_create_ip", "127.0.0.1"); // params.put("trade_type", TradeType.JSAPI.name()); // params.put("nonce_str", System.currentTimeMillis() / 1000 + ""); // params.put("notify_url", notifyUrl); // params.put("openid", openId); // //临时字段,判断是否为新版PDA创建的支付单 zhaowg 2017-12-15 // String attach = ""; // if(payOrderDTO.getIsNewPDACreate()!=null && payOrderDTO.getIsNewPDACreate()){ // attach = "isNewPDACreate"; // } // params.put("attach", attach); // // //是否支持信用卡支付 // if (configDTO.getIsPayNocredit() == 1) { // //不支持信用卡 // params.put("limit_pay", "no_credit"); // } // // // String sign = PaymentUtil.createSign(params, WxConfigUtil.decode(configDTO.getPayApiSecret())); // params.put("sign", sign); // logger.info("调用微信支付统一下单接口请求入参为:param=" + JSONObject.toJSONString(params)); // String xmlResult = PaymentApi.pushOrder(params); // logger.info("调用微信支付统一下单接口返回结果为:xmlResult=" + xmlResult); // Map result = PaymentUtil.xmlToMap(xmlResult); // String return_code = result.get("return_code"); // String return_msg = result.get("return_msg"); // if (StringUtils.isBlank(return_code) || !"SUCCESS".equals(return_code)) { // bizResult.setData("return_code=" + return_code + "; return_msg=" + return_msg); // bizResult.setErrCode(ErrorType.BIZ_ERROR); // bizResult.setErrMsg("调用微信支付异常,请稍后重试!"); // return bizResult; // } // String result_code = result.get("result_code"); // if (StringUtils.isBlank(result_code) || !"SUCCESS".equals(result_code)) { // bizResult.setData("result_code=" + result_code + "; return_msg=" + return_msg); // bizResult.setErrCode(ErrorType.BIZ_ERROR); // bizResult.setErrMsg("调用微信支付异常,请稍后重试!"); // return bizResult; // } // // 以下字段在return_code 和result_code都为SUCCESS的时候有返回 // String prepay_id = result.get("prepay_id"); // Map packageParams = new HashMap(); // packageParams.put("appId", configDTO.getAppid()); // packageParams.put("timeStamp", System.currentTimeMillis() / 1000 + ""); // packageParams.put("nonceStr", System.currentTimeMillis() + ""); // packageParams.put("package", "prepay_id=" + prepay_id); // packageParams.put("signType", "MD5"); // logger.info("生成签名钱的字符串为: param=" + packageParams.toString()); // String packageSign = PaymentUtil.createSign(packageParams, WxConfigUtil.decode(configDTO.getPayApiSecret())); // logger.info("获取到的密钥为: paternerKey=" + WxConfigUtil.decode(configDTO.getPayApiSecret())); // packageParams.put("paySign", packageSign); // //生成js 支付调用串 // String paySign = JSONObject.toJSON(packageParams).toString(); // logger.info("生成H5 调用支付串为:paySign=" + paySign); // bizResult.setErrCode(ErrorType.BIZ_SUCCESS); // bizResult.setData(paySign); // return bizResult; // } // //}