You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					189 lines
				
				7.3 KiB
			
		
		
			
		
	
	
					189 lines
				
				7.3 KiB
			| 
											3 years ago
										 | //package com.ynxbd.wx.wxfactory.payment.jsapi;
 | ||
|  | //
 | ||
|  | //import com.ynxbd.common.helper.common.ErrorHelper;
 | ||
|  | //import com.ynxbd.common.helper.common.JsonHelper;
 | ||
|  | //import com.ynxbd.common.result.JsonResult;
 | ||
|  | //import com.ynxbd.wx.wxfactory.bean.MedicalPayOrder;
 | ||
|  | //import com.ynxbd.wx.wxfactory.utils.WxRequestHelper;
 | ||
|  | //import lombok.extern.slf4j.Slf4j;
 | ||
|  | //
 | ||
|  | //import java.math.BigDecimal;
 | ||
|  | //import java.util.HashMap;
 | ||
|  | //import java.util.Map;
 | ||
|  | //
 | ||
|  | //@Slf4j
 | ||
|  | //public class Client {
 | ||
|  | //
 | ||
|  | //    /**
 | ||
|  | //     * 微信JSAPI下单
 | ||
|  | //     *
 | ||
|  | //     * @param appId        应用ID
 | ||
|  | //     * @param mchId        直连商户号
 | ||
|  | //     * @param description  商品描述
 | ||
|  | //     * @param out_trade_no 商户订单号
 | ||
|  | //     * @param time_expire  交易结束时间(yyyy-MM-DDTHH:mm:ss+TIMEZONE  示例值:2018-06-08T10:34:56+08:00)
 | ||
|  | //     * @param notify_url   通知地址
 | ||
|  | //     * @param totalFee     订单金额(元)
 | ||
|  | //     * @param openid       openid
 | ||
|  | //     * @param attach       附加数据
 | ||
|  | //     */
 | ||
|  | //    public MedicalPayOrder createOrder(String appId, String mchId, String description, String out_trade_no,
 | ||
|  | //                                       String time_expire, String attach, String notify_url, BigDecimal totalFee,
 | ||
|  | //                                       String openid) {
 | ||
|  | //
 | ||
|  | //        try {
 | ||
|  | //            JsonResult jsonResult = WxRequestHelper.postMdXml("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi", params -> {
 | ||
|  | //                params.put("appid", appId);
 | ||
|  | //                params.put("mchid", mchId);
 | ||
|  | //                params.put("description", description);
 | ||
|  | //                params.put("out_trade_no", out_trade_no);
 | ||
|  | //                if (time_expire != null) {
 | ||
|  | //                    params.put("time_expire", time_expire);
 | ||
|  | //                }
 | ||
|  | //                Map<String, Object> amountMap = new HashMap<>();
 | ||
|  | //                amountMap.put("total", totalFee.movePointRight(2)); // 分
 | ||
|  | //                params.put("amount", amountMap);
 | ||
|  | //
 | ||
|  | //                params.put("notify_url", notify_url);
 | ||
|  | //                params.put("openid", openid);
 | ||
|  | //
 | ||
|  | //                if (attach != null) {
 | ||
|  | //                    params.put("attach", attach);
 | ||
|  | //                }
 | ||
|  | //            });
 | ||
|  | //            log.info("[医保]下单返回:{}", JsonHelper.toJsonString(jsonResult));
 | ||
|  | //            if (!jsonResult.success()) {
 | ||
|  | //                return new MedicalPayOrder().createResult(jsonResult);
 | ||
|  | //            }
 | ||
|  | //            return jsonResult.dataMapToBean(MedicalPayOrder.class);
 | ||
|  | //        } catch (Exception e) {
 | ||
|  | //            ErrorHelper.println(e);
 | ||
|  | //        }
 | ||
|  | //        return null;
 | ||
|  | //    }
 | ||
|  | //
 | ||
|  | //
 | ||
|  | //    /**
 | ||
|  | //     * 查询订单
 | ||
|  | //     *
 | ||
|  | //     * @param mchId      直连商户号
 | ||
|  | //     * @param outTradeNo 商品描述
 | ||
|  | //     * @param transId    微信支付订单号
 | ||
|  | //     */
 | ||
|  | //    public MedicalPayOrder queryOrder(String mchId, String outTradeNo, String transId) {
 | ||
|  | //
 | ||
|  | //        try {
 | ||
|  | //            JsonResult jsonResult = null;
 | ||
|  | //
 | ||
|  | //            if (outTradeNo != null) {
 | ||
|  | //                jsonResult = WxRequestHelper.postMdXml("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/" + outTradeNo + "?" + mchId, params -> {
 | ||
|  | //                });
 | ||
|  | //
 | ||
|  | //            } else {
 | ||
|  | //                if (transId != null) {
 | ||
|  | //                    jsonResult = WxRequestHelper.postMdXml("https://api.mch.weixin.qq.com/v3/pay/transactions/id/" + transId + "?" + mchId, params -> {
 | ||
|  | //                    });
 | ||
|  | //                }
 | ||
|  | //            }
 | ||
|  | //
 | ||
|  | //            log.info("[医保]查询订单:{}", JsonHelper.toJsonString(jsonResult));
 | ||
|  | //            if (!jsonResult.success()) {
 | ||
|  | //                return new MedicalPayOrder().createResult(jsonResult);
 | ||
|  | //            }
 | ||
|  | //            return jsonResult.dataMapToBean(MedicalPayOrder.class);
 | ||
|  | //        } catch (Exception e) {
 | ||
|  | //            ErrorHelper.println(e);
 | ||
|  | //        }
 | ||
|  | //        return null;
 | ||
|  | //    }
 | ||
|  | //
 | ||
|  | //
 | ||
|  | //    /**
 | ||
|  | //     * 关闭订单
 | ||
|  | //     *
 | ||
|  | //     * @param mchId      直连商户号
 | ||
|  | //     * @param outTradeNo 商品描述
 | ||
|  | //     * @param transId    微信支付订单号
 | ||
|  | //     */
 | ||
|  | //    public MedicalPayOrder closeOrder(String mchId, String outTradeNo, String transId) {
 | ||
|  | //
 | ||
|  | //        try {
 | ||
|  | //            JsonResult jsonResult = WxRequestHelper.postMdXml(" https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/" + outTradeNo + "/close", params -> {
 | ||
|  | //                params.put("mchId", mchId);
 | ||
|  | //            });
 | ||
|  | //
 | ||
|  | //            log.info("[医保]关闭订单返回:{}", JsonHelper.toJsonString(jsonResult));
 | ||
|  | //            if (!jsonResult.success()) {
 | ||
|  | //                return new MedicalPayOrder().createResult(jsonResult);
 | ||
|  | //            }
 | ||
|  | //            return jsonResult.dataMapToBean(MedicalPayOrder.class);
 | ||
|  | //        } catch (Exception e) {
 | ||
|  | //            ErrorHelper.println(e);
 | ||
|  | //        }
 | ||
|  | //        return null;
 | ||
|  | //    }
 | ||
|  | //
 | ||
|  | //
 | ||
|  | //    /**
 | ||
|  | //     * 微信JSAPI下单
 | ||
|  | //     *
 | ||
|  | //     * @param outTradeNo 商品描述
 | ||
|  | //     * @param transId    微信支付订单号
 | ||
|  | //     */
 | ||
|  | //    public MedicalPayOrder refund(String outTradeNo, String transId, String outRefundNo, BigDecimal refundFee, BigDecimal totalFee, String reason, String notify_url) {
 | ||
|  | //
 | ||
|  | //        try {
 | ||
|  | //            JsonResult jsonResult = WxRequestHelper.postMdXml("https://api.mch.weixin.qq.com/v3/refund/domestic/refunds", params -> {
 | ||
|  | //                params.put("transaction_id", transId);
 | ||
|  | //                params.put("out_trade_no", outTradeNo);
 | ||
|  | //                params.put("out_refund_no", outRefundNo);
 | ||
|  | //
 | ||
|  | //                Map<String, Object> amountMap = new HashMap<>();
 | ||
|  | //                amountMap.put("refund", refundFee.movePointRight(2)); // 分
 | ||
|  | //                amountMap.put("total", totalFee.movePointRight(2)); // 分
 | ||
|  | //                amountMap.put("currency", "CNY"); // 分
 | ||
|  | //                params.put("amount", amountMap);
 | ||
|  | //
 | ||
|  | //                if (notify_url != null) {
 | ||
|  | //                    params.put("notify_url", notify_url);
 | ||
|  | //                }
 | ||
|  | //
 | ||
|  | //                if (reason != null) {
 | ||
|  | //                    params.put("reason", reason);
 | ||
|  | //                }
 | ||
|  | //            });
 | ||
|  | //            log.info("[微信]退费返回:{}", JsonHelper.toJsonString(jsonResult));
 | ||
|  | //            if (!jsonResult.success()) {
 | ||
|  | //                return new MedicalPayOrder().createResult(jsonResult);
 | ||
|  | //            }
 | ||
|  | //            return jsonResult.dataMapToBean(MedicalPayOrder.class);
 | ||
|  | //        } catch (Exception e) {
 | ||
|  | //            ErrorHelper.println(e);
 | ||
|  | //        }
 | ||
|  | //        return null;
 | ||
|  | //    }
 | ||
|  | //
 | ||
|  | //
 | ||
|  | //    /**
 | ||
|  | //     * 查询退费订单
 | ||
|  | //     *
 | ||
|  | //     * @param outRefundNo 退费订单号
 | ||
|  | //     */
 | ||
|  | //    public MedicalPayOrder queryRefund(String outRefundNo) {
 | ||
|  | //
 | ||
|  | //        try {
 | ||
|  | //            JsonResult jsonResult = WxRequestHelper.postMdXml("https://api.mch.weixin.qq.com/v3/refund/domestic/refunds/" + outRefundNo, params -> {
 | ||
|  | //
 | ||
|  | //            });
 | ||
|  | //            log.info("[微信]查询退费订单:{}", JsonHelper.toJsonString(jsonResult));
 | ||
|  | //            if (!jsonResult.success()) {
 | ||
|  | //                return new MedicalPayOrder().createResult(jsonResult);
 | ||
|  | //            }
 | ||
|  | //            return jsonResult.dataMapToBean(MedicalPayOrder.class);
 | ||
|  | //        } catch (Exception e) {
 | ||
|  | //            ErrorHelper.println(e);
 | ||
|  | //        }
 | ||
|  | //        return null;
 | ||
|  | //    }
 | ||
|  | //}
 |