微信支付后台:
只有这里设置了,程序中才能使用这个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