| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.order.domain.dto.WechatPaymentRefundDto; |
| | | import com.ruoyi.order.domain.dto.WeixinPaymentNotifyDto; |
| | | import com.ruoyi.order.domain.vo.PaymentDelaytransHFTXVo; |
| | | import com.ruoyi.order.domain.vo.WeixinPaymentNotifyVo; |
| | | import com.ruoyi.order.domain.vo.WeixinPaymentRefundVo; |
| | |
| | | import java.security.Signature; |
| | | import java.security.spec.PKCS8EncodedKeySpec; |
| | | import java.security.spec.X509EncodedKeySpec; |
| | | import java.text.NumberFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | |
| | | */ |
| | | public static R<JSONObject> weixinPayment(String req_seq_id, String goods_desc, Double trans_amt, String sub_openid, String notify_url){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | NumberFormat numberInstance = NumberFormat.getInstance(); |
| | | //最大两位小数 |
| | | numberInstance.setMaximumFractionDigits(2); |
| | | String url = "https://api.huifu.com/v2/trade/payment/jspay"; |
| | | JSONObject data = new JSONObject(); |
| | | data.put("req_date", sdf.format(new Date())); |
| | |
| | | data.put("huifu_id", huifu_id); |
| | | data.put("goods_desc", goods_desc); |
| | | data.put("trade_type", "T_MINIAPP"); |
| | | data.put("trans_amt", numberInstance.format(trans_amt)); |
| | | data.put("trans_amt", String.format("%.2f", trans_amt)); |
| | | |
| | | JSONObject wx_data = new JSONObject(); |
| | | wx_data.put("sub_appid", sub_appid); |
| | |
| | | headers.put("Content-type","application/json; charset=utf-8"); |
| | | headers.put("Accept", "application/json"); |
| | | post.addHeaders(headers); |
| | | System.err.println(JSON.toJSONString(body)); |
| | | post.body(body.toJSONString()); |
| | | HttpResponse execute = post.execute(); |
| | | String result1 = execute.body(); |
| | | execute.close(); |
| | | if(StringUtils.hasLength(result1)){ |
| | | JSONObject result = JSONObject.parseObject(result1); |
| | | String result_data = result.getString("data"); |
| | | String result_sign = result.getString("sign"); |
| | | boolean verify = verify(result_data, result_sign); |
| | | if(!verify){ |
| | | return R.fail("结果验签失败"); |
| | | } |
| | | JSONObject resultData = result.getJSONObject("data"); |
| | | String resp_code = resultData.getString("resp_code"); |
| | | String resp_desc = resultData.getString("resp_desc"); |
| | |
| | | |
| | | /** |
| | | * 微信支付回调数据处理 |
| | | * @param jsonObject |
| | | * @return |
| | | */ |
| | | public static R<WeixinPaymentNotifyVo> weixinPaymentNotify(JSONObject jsonObject){ |
| | | String sign = jsonObject.getString("sign"); |
| | | JSONObject resp_data = jsonObject.getJSONObject("resp_data"); |
| | | String resp_code = jsonObject.getString("resp_code"); |
| | | String resp_desc = jsonObject.getString("resp_desc"); |
| | | public static R<WeixinPaymentNotifyVo> weixinPaymentNotify(WeixinPaymentNotifyDto dto){ |
| | | String sign = dto.getSign(); |
| | | JSONObject resp_data = JSON.parseObject(dto.getResp_data()); |
| | | String resp_code = dto.getResp_code(); |
| | | String resp_desc = dto.getResp_desc(); |
| | | if("00000000".equals(resp_code)){ |
| | | String code = resp_data.getString("resp_code"); |
| | | String desc = resp_data.getString("resp_desc"); |
| | | if("00000000".equals(code)){ |
| | | if(!"00000000".equals(code)){ |
| | | return R.fail(desc); |
| | | } |
| | | WeixinPaymentNotifyVo vo = new WeixinPaymentNotifyVo(); |
| | |
| | | * @param req_seq_id 请求流水号 |
| | | * @param ord_amt 退款金额 |
| | | * @param org_req_date 原交易请求日期yyyyMMdd |
| | | * @param org_party_order_id 原交易微信支付宝的商户单号 |
| | | * @param org_req_seq_id 原交易请求流水号 |
| | | * @param notify_url 异步通知地址 |
| | | * @return |
| | | */ |
| | | public static R<String> weixinPaymentRefund(String req_seq_id, Double ord_amt, String org_req_date, String org_party_order_id, String notify_url){ |
| | | public static R<String> weixinPaymentRefund(String req_seq_id, Double ord_amt, String org_req_date, String org_req_seq_id, String notify_url){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | NumberFormat numberInstance = NumberFormat.getInstance(); |
| | | //最大两位小数 |
| | | numberInstance.setMaximumFractionDigits(2); |
| | | String url = "https://api.huifu.com/v2/trade/payment/scanpay/refund"; |
| | | JSONObject data = new JSONObject(); |
| | | data.put("req_date", sdf.format(new Date())); |
| | | data.put("req_seq_id", req_seq_id); |
| | | data.put("huifu_id", huifu_id); |
| | | data.put("ord_amt", ord_amt); |
| | | data.put("ord_amt", String.format("%.2f", ord_amt)); |
| | | data.put("org_req_date", org_req_date); |
| | | data.put("org_party_order_id", org_party_order_id); |
| | | data.put("org_req_seq_id", org_req_seq_id); |
| | | data.put("notify_url", notify_url); |
| | | |
| | | JSONObject body = new JSONObject(); |
| | |
| | | headers.put("Accept", "application/json"); |
| | | post.addHeaders(headers); |
| | | post.body(body.toJSONString()); |
| | | System.err.println(JSON.toJSONString(body)); |
| | | HttpResponse execute = post.execute(); |
| | | String result1 = execute.body(); |
| | | execute.close(); |
| | | if(StringUtils.hasLength(result1)){ |
| | | JSONObject result = JSONObject.parseObject(result1); |
| | | String result_data = result.getString("data"); |
| | | String result_sign = result.getString("sign"); |
| | | boolean verify = verify(result_data, result_sign); |
| | | if(!verify){ |
| | | return R.fail("结果验签失败"); |
| | | } |
| | | JSONObject resultData = result.getJSONObject("data"); |
| | | String resp_code = resultData.getString("resp_code"); |
| | | String resp_desc = resultData.getString("resp_desc"); |
| | | String trans_stat = resultData.getString("trans_stat"); |
| | | //交易受理成功;注:交易状态以trans_stat为准; |
| | | String success1 = "00000000"; |
| | | if(success1.equals(resp_code)){ |
| | | String success2 = "00000100"; |
| | | if(success1.equals(resp_code) || success2.equals(resp_code)){ |
| | | String req_seq_id1 = resultData.getString("req_seq_id"); |
| | | return R.ok(req_seq_id1); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 微信支付退款回调通知 |
| | | * @param jsonObject |
| | | * @return |
| | | */ |
| | | public static R<WeixinPaymentRefundVo> weixinPaymentRefundNotify(JSONObject jsonObject){ |
| | | String sign = jsonObject.getString("sign"); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | String resp_code = data.getString("resp_code"); |
| | | String resp_desc = data.getString("resp_desc"); |
| | | public static R<WeixinPaymentRefundVo> weixinPaymentRefundNotify(WechatPaymentRefundDto dto){ |
| | | String sign = dto.getSign(); |
| | | JSONObject data = JSON.parseObject(dto.getResp_data()); |
| | | String resp_code = data.getString("sub_resp_code"); |
| | | String resp_desc = data.getString("sub_resp_desc"); |
| | | if("00000000".equals(resp_code)){ |
| | | WeixinPaymentRefundVo vo = new WeixinPaymentRefundVo(); |
| | | vo.setReqSeqId(data.getString("req_seq_id")); |