/*** 微信获取prepay_id 同时下单* * @return* @throws Exception*/@RequestMapping(value = "/getPrepayId", method = RequestMethod.GET)public @ResponseBody Map<String, Object> getPrepayId(HttpServletRequest request, String sn) throws Exception {Map<String, Object> resultMap = new HashMap<String, Object>();Order order = orderService.findBySn(sn);System.out.println("sn==========="+sn);Member member = memberService.getCurrent();if (order == null || !member.equals(order.getMember()) || order.getPaymentMethod() == null|| order.getAmountPayable().compareTo(BigDecimal.ZERO) <= 0) {System.out.println(ERROR_VIEW);resultMap.put("error_message", ERROR_VIEW);resultMap.put("success", 1);return resultMap;}if (PaymentMethod.Method.online.equals(order.getPaymentMethod().getMethod())) {if (orderService.isLocked(order, member, true)) {System.out.println(Message.warn("shop.order.locked"));resultMap.put("error_message", Message.warn("shop.order.locked"));resultMap.put("success", 1);return resultMap;}PaymentPlugin paymentPlugin = pluginService.getPaymentPlugin("wxpayPubPaymentPlugin");if (paymentPlugin != null) {if (paymentPlugin == null || !paymentPlugin.getIsEnabled()) {System.out.println(ERROR_VIEW);resultMap.put("error_message", ERROR_VIEW);resultMap.put("success", 1);return resultMap;}// 添加支付记录PaymentLog paymentLogtmp = paymentLogService.findBySn(order.getSn());System.out.println("sn==========="+order.getSn());System.out.println("paymentLogtmp==========="+paymentLogtmp);if(paymentLogtmp==null){PaymentLog paymentLog = new PaymentLog();paymentLog.setSn(order.getSn());paymentLog.setType(PaymentLog.Type.payment);paymentLog.setStatus(PaymentLog.Status.wait);paymentLog.setFee(paymentPlugin.calculateFee(order.getAmountPayable()));paymentLog.setAmount(paymentPlugin.calculateAmount(order.getAmountPayable()));paymentLog.setPaymentPluginId(paymentPlugin.getId());paymentLog.setPaymentPluginName(paymentPlugin.getName());paymentLog.setMember(member);paymentLog.setOrder(order);paymentLogService.save(paymentLog);}Map<String, String> paramMap = new HashMap<String, String>();paramMap.put("out_trade_no", order.getSn());paramMap.put("total_fee",order.getAmount() != null ? paymentPlugin.calculateAmount(order.getAmountPayable()).multiply(new BigDecimal("100")).toBigInteger().toString() : "0");paramMap.put("openid", member.getOpenId());String paramXms =CommonPayment.getPrepayIdParam(request, paramMap).toString();String str = HttpRequest.sendPost(CommonWeChat.PAYMENT_GET_PREPAYID_URL, paramXms);str = str.replaceAll("<![CDATA[|]]>", "");SortedMap<String, String> dataMap = CommonPayment.xmlToMap(str);SortedMap<String, String> data = new TreeMap<String, String>();if (dataMap.get("return_code").equalsIgnoreCase("SUCCESS")&& dataMap.get("result_code").equalsIgnoreCase("SUCCESS")) {data.put("appId", CommonWeChat.APPID.trim());data.put("timeStamp", Sha1Util.getTimeStamp().trim());data.put("nonceStr", Sha1Util.getNonceStr().trim());data.put("package", "prepay_id=" + dataMap.get("prepay_id").trim());data.put("signType", CommonWeChat.SIGNTYPE.trim());data.put("paySign", CommonPayment.getMD5Sign(data).trim());resultMap.put("success", 0);resultMap.put("resultData", data);} else if (dataMap.get("return_code").equalsIgnoreCase("FAIL")) {System.out.println(dataMap.get("return_msg"));resultMap.put("error_message", dataMap.get("return_msg"));resultMap.put("success", 1);} else if (dataMap.get("result_code").equalsIgnoreCase("FAIL")) {System.out.println(dataMap.get("err_code_des"));resultMap.put("error_message", dataMap.get("err_code_des"));resultMap.put("success", 1);} else {System.out.println(dataMap.get("数据有误"));resultMap.put("error_message", "数据有误");resultMap.put("success", 1);}} else {System.out.println(ERROR_VIEW);resultMap.put("error_message", ERROR_VIEW);resultMap.put("success", 1);return resultMap;}}return resultMap;}@RequestMapping(value = "/m_weixinNotify")public String m_weixinNotify(String sn, HttpServletRequest request, ModelMap model) {System.out.println("sn====="+sn);PaymentLog paymentLog = paymentLogService.findBySn(sn);System.out.println("paymentLog====="+paymentLog);model.addAttribute("paymentLog", paymentLog);return "payment/plugin_notify";}/*** 微信支付成功通知* * @return* @throws Exception*/@RequestMapping(value = "/paySuccess")public void paySuccess(HttpServletRequest request, HttpServletResponse response) throws Exception {System.out.println("paySuccess: begin\n");try {ServletInputStream in = request.getInputStream();StringBuffer buff = new StringBuffer();try {byte[] b = new byte[4096];for (int length; (length = in.read(b)) != -1;) {buff.append(new String(b, 0, length));}} catch (IOException e) {System.out.println("streamToString : === " + e.getMessage());buff = buff.delete(0, buff.length());e.printStackTrace();}String result = buff.toString();System.out.println("result:== " + result);System.out.println("xStreamUtil begin...");if (result != null && !result.equals("")) {Map<String, String> map = CommonPayment.xmlToMap(result);System.out.println("map:" + map);for (Object keyValue : map.keySet()) {
//                  System.out.println(keyValue + "=" + map.get(keyValue));}System.out.println("result_code:" + map.get("result_code").equalsIgnoreCase("SUCCESS"));if (map.get("result_code").equalsIgnoreCase("SUCCESS")) {
//                  String sign = CommonPayment.SuccessSign(map, CommonWeChat.MCH_KEY);
//                  System.out.println("215 sign=" + map.get("sign") + " APP_PAYKRY=" + sign);
//                  if (sign != null && map.get("sign").equals(sign)) {String out_trade_no = map.get("out_trade_no");String total_fee = map.get("total_fee");//处理订单sendToCFT("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>", response);
//                  }}}sendToCFT("<xml><return_code><![CDATA[FAIL]]></return_code></xml>", response);} catch (Exception ex) {System.out.println("paySuccess Exception = " + ex.getMessage());ex.printStackTrace();}System.out.println("paySuccess  === end\n");}public void sendToCFT(String msg, HttpServletResponse response) throws IOException {String strHtml = msg;PrintWriter out = response.getWriter();out.println(strHtml);out.flush();out.close();}

微信支付获取prepay_id以及回调地址相关推荐

  1. php获取prepay_id时报错,微信支付获取prepay_id返回签名错误,官方demo中的签名方法MD5验证有问题...

    引用官方V3微信支付PHP版的demo做的改动,在获取prepay_id发现总是返回签名错误,经与腾讯官方的"微信公众平台支付接口调试工具"对比发现MD5不一样,找到demo中代码 ...

  2. php开发微信支付获取用户地址

    使用微信获取地址信息是和微信支付一道申请的,微信支付申请通过,就可以使用该功能. 微信商城中,使用微信支付获取用户的收货地址,可以省略用户输入地址信息的繁复流程,提高用户体验. 但是可能是因为牵扯到用 ...

  3. PHP微信支付获取回调数据

    微信支付获取回调数据 微信回调接口比较麻烦一点就是不方便测试 微信支付回调函数都是使用以下变量获取POST数据: php配置中,必须启用 always_populate_raw_post_data / ...

  4. PHP处理微信支付成功后的回调处理

    PHP处理微信支付成功后的回调处理 微信支付成功后我们可通过设置的回调地址中来处理 public function wx_notify(){$xml = file_get_contents(" ...

  5. 微信支付开发(6) 收货地址共享接口

    关键字:微信支付 收货地址共享 作者:方倍工作室 原文: http://www.cnblogs.com/txw1958/p/weixin-editAddress.html 请看新版教程  微信支付开发 ...

  6. java微信支付v3系列——8.微信支付之退款成功回调

    目录 java微信支付v3系列--1.微信支付准备工作 java微信支付v3系列--2.微信支付基本配置 java微信支付v3系列--3.订单创建准备操作 java微信支付v3系列--4.创建订单的封 ...

  7. 微信app支付统一下单设置回调地址php,微信支付配置回调地址

    需要超级管理员帐号登录才可操作 1) 所有使用公众号支付方式发起支付请求的链接地址,都必须在支付授权目录之下: 2) 支付授权目录最多可以设置5个目录 3) 头部要包含http或https,须细化到二 ...

  8. php获取微信账单,微信支付获取回调数据

    微信回调接口比较麻烦一点就是不方便测试 微信支付回调函数都是使用以下变量获取POST数据: php配置中,必须启用 always_populate_raw_post_data//php.ini 配置 ...

  9. Android开发之微信支付获取签名小工具分享

    老套路,先看图: 大家支付的时候下面的签名一般是如何弄出来的? 1.一个字母一个字母手写?容易出错 2.用QQ截图然后使用QQ的图片文字识别功能?(我一般用这个) 但是都特别麻烦,于是乎我自己把微信官 ...

最新文章

  1. C++虚继承和虚基类详解(一)
  2. python zookeeper_ZooKeeper的安装以及客户端Kazoo(Python语言)的安装与使用
  3. [转]ASP.NET会话(Session)保存模式
  4. python画相关性可视化图_Python可视化很简单,一文教你绘制饼图、极线图和气泡图...
  5. 牛客题霸 [ 最长递增子序列] C++题解/答案
  6. jQuery实现复选框的全选和反选:
  7. 修改Netbeas的注释结构
  8. Redis面试 - redis 的雪崩和穿透?
  9. [译] Go 并发编程基础
  10. 【LeetCode】剑指 Offer 43. 1~n 整数中 1 出现的次数
  11. 省公务员县公安局,县编办,县政府办,县保密局,这几岗位怎么选?
  12. python re正则_正则表达式+Python re模块详解
  13. ffmpeg生成缩略图
  14. h5案例分享 京东:有爱圣诞 无限京喜
  15. Cybersource支付流程设计
  16. 2021年金属非金属矿山支柱考试题库及金属非金属矿山支柱找解析
  17. 基于PHP+MYSQL的成绩查询系统(含源码)
  18. win10自带ubuntu桌面_windows10开启 linux子系统桌面,巨详细,值得一藏
  19. 万豪国际成立全球清洁卫生委员会,推行更高标准清洁消毒措施
  20. 汉诺塔(hanoi)

热门文章

  1. 练习2-4:重新编写函数squeeze(s1,s2),将字符串s1中的任何字符与字符串时s2中的字符匹配的字符都删除
  2. SSH公钥原理(密钥,秘钥,私钥)(看了还是懵逼啊!)
  3. 基于SSM实现企业生资源管理系统-ERP系统
  4. branch什么意思中文翻译_给宝宝读英文绘本,到底要不要中文翻译?
  5. java丐帮_java包的问题
  6. 大道至简之一:如何准确把握趋势
  7. 爬虫(利用正则表达式爬取百度新闻(淘宝))
  8. 深演智能数智化 “三角魔方”浮出水面,企业征战数字化转型沙场的最新秘密武器?...
  9. 最新网易微专业 Android开发系列
  10. 星巴克猫爪杯开售遭哄抢 淘宝同款比比皆是真假难辨