zoukankan      html  css  js  c++  java
  • jfinal微信支付

    private static final String appid = PropKit.get("appid"); //应用ID
    private static final String mch_id = PropKit.get("mch_id"); //商户号
    private static final String paternerKey = PropKit.get("paternerkey");  //支付密钥
    private static final String notify_url = PropKit.get("notify_url");  //通知地址
    
        public RetKit weixinPay(String ip,String amount,Map<String,Object> map){
            // 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
            //调起微信支付,统一下单
            Map<String,String> params = new HashMap<String,String>();
            params.put("appid", appid);
            params.put("mch_id", mch_id);
            params.put("body", "魅格");
            params.put("out_trade_no", new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+(int)(Math.random()*90000+10000)); //订单编号
            params.put("total_fee", amount); //订单金额  单位为分
            if(StrKit.isBlank(ip)){
                ip = "127.0.0.1";
            }
            params.put("spbill_create_ip", ip);  //终端ip
            params.put("trade_type", TradeType.APP.name()); //交易类型app:手机app支付,NATIVE:返回支付连接,可转成二维码客户扫描支付
            params.put("nonce_str",  System.currentTimeMillis() / 1000 + ""); //随机字符串
            params.put("notify_url", notify_url); //支付后通知回调地址
            params.put("attach", map.toString()); //附加数据,支付后原数据返回
            String sign = PaymentKit.createSign(params, paternerKey);    //生成签名
            params.put("sign", sign);
            //下单
            String xmlResult = PaymentApi.pushOrder(params);
            System.out.println("下单后结果"+xmlResult);
            Map<String,String> result = PaymentKit.xmlToMap(xmlResult);
            
            String return_code = result.get("return_code");
            String return_msg = result.get("return_msg");
            if(StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)){
                return RetKit.fail(return_msg);
            }
            
            String result_code = result.get("result_code");
            if(StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)){
                return RetKit.fail(return_msg);
            }
            return RetKit.okData(xmlResult);
        }

    统一下单文档地址

    2,支付结果回调,微信不保证会一定返回结果通知,正常会调用多次

    获取支付结果

    String xmlMsg = HttpKit.readData(getRequest());

    public RetKit weixinPay_notify(String xmlMsg){
            // 支付结果通用通知文档: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
            System.out.println("支付通知"+xmlMsg);
            Map<String,String> result = PaymentKit.xmlToMap(xmlMsg);
            String result_code = result.get("result_code");
             //总金额
            String total_fee = result.get("total_fee");
            Double amount = Double.valueOf(total_fee)*0.01;
            //商户订单号
            String trade_no = result.get("out_trade_no");
            //微信支付订单号
            String transaction_id = result.get("transaction_id");
            //附近数据
            String attach = result.get("attach");
            //支付完成时间
            //String time_end = result.get("time_end");
            // 注意重复通知的情况,同一订单号可能收到多次通知,请注意一定先判断订单状态
            // 避免已经成功、关闭、退款的订单被再次更新
            if(PaymentKit.verifyNotify(result, paternerKey)){
                if("SUCCESS".equals(result_code)){
                    //添加各种流水
                    addBills(attach,Reward.access_weixin, amount.toString(), trade_no, transaction_id);
                }
            }
            return RetKit.ok();
        }
    支付结果通用通知文档
  • 相关阅读:
    java RSA加密解密
    spring boot 错误处理机制
    Redis 服务常见的几个错误解决方案
    Nginx目录遍历功能时间相差8小时
    翻过大山越过海洋看到了什么
    【分享】分层明确高度定制化的 Python Flask MVC
    编程浪子客服系统开源啦
    快速搭建一个直播Demo
    免费为网站加上HTTPS
    Mac 下安装Fiddler抓包工具
  • 原文地址:https://www.cnblogs.com/suruozhong/p/6632096.html
Copyright © 2011-2022 走看看