手把手教你完成微信H5支付

关于微信支付支付,个人觉得相比支付宝复杂的太多了,但是慢慢理解起来还是很简单的

1,首先准备工作,下方是一个时序图,认真看,图看懂了做起来真的很简单

,

2,第二按照上图说明,开始下单时,调用微信下单接口是需要准备一下几个参数

APIKEY ---------  支付秘钥(微信商户平台可查,需要自己设置)

appid -----   商户ID(微信商户平台可查)

body-------   商品名称

mch_id -----     支付商户号(微信商户平台可查)

nonce_str ---------- 随机字符串

/**
     * 获取随机字符串 Nonce Str
     *
     * @return String 随机字符串
     */
    public static String generateNonceStr() {
        char[] nonceChars = new char[32];
        for (int index = 0 ; index < nonceChars.length ; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars);
    }

out_trade_no------------   订单号

spbill_create_ip ------------请求IP

/**
     * 获取用户实际ip
     * @param request
     * @return
     */
    public static String getIpAddr(HttpServletRequest request) {
        String ipAddress = request.getHeader("x-forwarded-for");
        if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getHeader("Proxy-Client-IP");
        }
        if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getRemoteAddr();
            if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) {
                //根据网卡取本机配置的IP  
                InetAddress inet = null;
                try {
                    inet = InetAddress.getLocalHost();
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                }
                ipAddress = inet.getHostAddress();
            }
        }
        //对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割  
        if (ipAddress != null && ipAddress.length() > 15) { //"***.***.***.***".length() = 15  
            if (ipAddress.indexOf(",") > 0) {
                ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
            }
        }
        return ipAddress;
    }

total_fee------------ //,字符串类型,获取金额,单位分

trade_type -------------------//支付类型,H5就是  "MWEB"

scene_info  -------------------  //{\"h5_info\": {\"type\":\"Wap\",\"wap_url\": \"https://www.chujian.live\",\"wap_name\": \"chongzhi\"}}    这个话里面 type就是Wap   wap_url--指的是你们官网地址 ,wap_name 就是网站名称

notify_url   ----------------- //此路径是微信服务器调用支付结果带了一大批参数多次请

  • 7
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值