微信支付开发(只针对公众号里的h5支付JSAPI)

微信支付后台:

https://pay.weixin.qq.com

只有这里设置了,程序中才能使用这个key

 /**
     * 微信支付统一下单接口
     *
     * @param userOrder 订单信息
     * @return
     * @throws Exception
     */
    public WebResult weixinPay(UserOrder userOrder, String payType, String ip) throws Exception {
        System.out.println("请求参数如下:");
        System.out.println("订单信息:"+userOrder.toString());
        System.out.println("支付方式payType:"+payType);
        System.out.println("-----------------------传递来的真实ip:------------" + ip);
        // 账号信息
        String appId = Configure.getAppid();
        // 商业号
        String mchId = Configure.getMchid();
        // key
        String key = Configure.getKey();
        // 随机字符串
        String currTime = PayCommonUtil.getCurrTime();
        String strTime = currTime.substring(8, currTime.length());
        String strRandom = PayCommonUtil.buildRandom(4) + "";
        String nonceStr = strTime + strRandom;
        // 商品名称
        String body = "LOVZVZU-商城";//这里非常重要,腾讯有格式要求
        // 价格 注意:价格的单位是分
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);



        //多比子订单
        Double totalprice = 0d;
        List<UserOrder> userOrders = orderService.select(1, 1,
        null, null, null,
        null, null, null,
                userOrder.getOrderno(), null);
        for (int i = 0; i < userOrders.size(); i++) {
            UserOrder userOrder1 = userOrders.get(i);
             totalprice += userOrder1.getPrice();
        }
        System.out.println("订单总额度:"+totalprice);

        List<AdminUser> userByWxid = adminUserService.findUserByWxid(userOrder.getCustomeropenid());
        if (userByWxid != null&&userByWxid.size()>0) {
            AdminUser adminUser = userByWxid.get(0);
            Double balance = adminUser.getBalance();
            System.out.println("用户余额:"+balance);
            if (balance>=totalprice){
                totalprice = 0d;
            }else {
                totalprice = totalprice - balance;
            }
        }
        System.out.println("最后需要支付额度:"+totalprice);
        /**
         *  1、交易金额
         *         交易金额默认为人民币交易,接口中参数支付金额单位为【分】,参数值不能带小数。对账单中的交易金额单位为【元】。
         *
         *         外币交易的支付金额精确到币种的最小单位,参数值不能带小数点。
          */

        String orderPrice = nf.format(totalprice.doubleValue()*100);

        // 查询订单数据表获取订单信息
        // 回调接口
        String notify_url = "http://xxxxxx/payWeixin/weixinNotify";
        String time_start = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        Calendar ca = Calendar.getInstance();
        ca.setTime(new Date());
        ca.add(Calendar.DATE, 1);
        String time_expire = new SimpleDateFormat("yyyyMMddHHmmss").format(ca.getTime());

        SortedMap<Object, Object> packageParams = new TreeMap<Object, Object>();
                                packageParams.put("a
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值