微信公众平台注册-申请微信支付

package com.cn.config;import com.cn.controller.WXPayController;
import com.github.wxpay.sdk.WXPayUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.util.HashMap;
import java.util.Map;/*** @Descripation 微信支付* @Date 2019-08-02 9:26* @since 1.0**/
public class WXUtils {private static final Logger logger = LoggerFactory.getLogger(WXPayController.class);//从你的微信平台获取private static final String appid = "";private static final String mch_id = " ";private static final String partnerkey = ""; //商户秘钥/* ** @Description 调用统一下单接口* param 1 商品订单号  2 total_fee 支付金额  订单号前端传,金额必须后端查  订单号32位*/public static Map unifyPay(String out_trade_no, String total_fee) {String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";Map<String, String> param = new HashMap<>();param.put("appid", appid);param.put("mch_id", mch_id);String nonce_str = WXPayUtil.generateNonceStr();param.put("nonce_str", nonce_str);param.put("body", "");param.put("out_trade_no", out_trade_no);param.put("total_fee", total_fee);param.put("spbill_create_ip", "127.0.0.1");//随便写param.put("notify_url", "");//回调地址随便写param.put("trade_type", "NATIVE");Map<String, String> resultMap = null;try {String xmlParam = WXPayUtil.generateSignedXml(param, partnerkey);//生成带签名的xmllogger.error("这是生成的xml:{}", xmlParam);String result = HttpUtils.postJsonRequest(url, xmlParam);resultMap = WXPayUtil.xmlToMap(result);logger.error("统一下单返回状态:{}", resultMap.get("return_code"));logger.error("统一下单返回信息:{}", resultMap.get("return_msg"));logger.error("二维码链接地址:{}", resultMap.get("code_url"));} catch (Exception e) {e.printStackTrace();}return resultMap;}/* ** @Description 查询订单接口*/public static Map<String, String> queryOrder(String out_trade_no) {String url = "https://api.mch.weixin.qq.com/pay/orderquery";Map<String, String> param = new HashMap<>();param.put("appid", appid);param.put("mch_id", mch_id);String nonce_str = WXPayUtil.generateNonceStr();param.put("nonce_str", nonce_str);param.put("out_trade_no", out_trade_no);Map<String, String> resultMap = null;try {String xmlParam = WXPayUtil.generateSignedXml(param, partnerkey);String result = HttpUtils.postJsonRequest(url, xmlParam);resultMap = WXPayUtil.xmlToMap(result);logger.error("查询订单返回状态:{}", resultMap.get("return_code"));logger.error("查询订单返回信息:{}", resultMap.get("return_msg"));logger.error("支付返回状态:{}", resultMap.get("trade_state"));} catch (Exception e) {e.printStackTrace();}return resultMap;}}

HttpUtils有需要的可以从我的资源里下载

package com.cn.controller;import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;import java.util.Map;/*** @Descripation* @since 1.0**/
@RestController
@RequestMapping("/WXPay")
@CrossOrigin
@Api(description = "微信支付")
public class WXPayController {@RequestMapping(value = "/OrderWXPay", method = RequestMethod.POST)@ApiOperation("微信支付 参数 1 订单号 订单号必须32位  ")@ApiImplicitParams({@ApiImplicitParam("订单号")})public Object orderWXPay(String out_trade_no) {//根据订单号去数据库查询金额 如果查不到 说明订单号非法return//支付金额Double order_limit = payOrder.getOrder_limit();int order_money = (int) (order_limit * 100);String total_fee = String.valueOf(order_money);Map map = WXUtils.unifyPay(out_trade_no, total_fee);if ("SUCCESS".equals(map.get("return_code"))) {map.put("money", String.valueOf(order_limit));return ResultMsg.ResultMsg(map,200,"下单成功");}return ResultMsg.ResultMsg(null,500, "订单异常");}@RequestMapping(value = "/OrderWXPayStatus", method = RequestMethod.POST)@ApiOperation("微信支付状态 查询订单接口   参数 订单号 ")@ApiImplicitParams({@ApiImplicitParam("订单号")})public Object orderWXPayStatus(String out_trade_no) {ResultMsg rm = null;int num = 0;while (true) {Map<String, String> resultMap = WXUtils.queryOrder(out_trade_no);if (resultMap == null) {return ResultMsg.ResultMsg(false,100, "支付错误");}if (resultMap.get("trade_state").equals("SUCCESS")) {//成功后的逻辑return ResultMsg.ResultMsg(true,200, "支付成功");}try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}num++;if (num > 200) {return ResultMsg.ResultMsg(false,300, "支付超时");}}}}

实现微信支付wxpay相关推荐

  1. 小程序微信支付功能开发

    关于小程序内唤起微信支付功能,不同人有不同的思路,有嵌套H5页面的,也有跳转第三方链接网站的,也有放收钱码等图片的. 今天讲一下微信原生的微信支付功能基础版块,支付页面和支付逻辑. 先上个效果图: 页 ...

  2. 微信小程序--微信支付流程

    今天做微信支付,记录一下 微信支付,对于我们前端来说还是比较简单的,知道大致流程之后,调用api,进行相应提示即可 使用微信支付,首先得是企业级用户,也就是有营业执照的,有两种注册方式: ①公众号注册 ...

  3. 前端 VUE 微信支付 JSAPI

    在威信公众号之中的产品H5页面,在购买时需要直接唤起微信支付,完成投保.核保流程.今天分享自己在唤起微信支付中的一些体会,希望可以帮助到大家. 先给大家将官方的说明文档附上,感兴趣的可以直接看看    ...

  4. 微信支付-java实现微信支付-后端篇

    微信支付系列文章 微信支付-java后端实现 微信支付-vue 前端实现 java demo: 下载地址文章底部 技术栈 Spring boot java XML (微信在http协议中数据传输方案) ...

  5. JSAPI网页授权-微信支付-微信退款-商户平台Java对接

    简介: 首先,对接微信支付要知道需要什么参数,然后等我们拿到这些需要的参数.就要开始怎么去做.微信有专门的支付dome,可惜我才疏学浅,没怎么看懂(哭泣~).不过里面的有一些工具类是我们所需要的. 这 ...

  6. 微信内网站微信支付对接

    文章包括以下内容 支付场景简介 第一步:申请微信支付申请(注册微信支付商户号) 第二步:获取商户号的支付参数 第三步:SDK下载(java版本) 第四步:支付过程了解 第五步:开始设计和编码 支付场景 ...

  7. jsSdk 微信配置config,调起微信支付

    话不多说,首先第一步,获取config需要的参数 appid,noncestr ,timestamp ,url ,signature 1.编写controller /*** 微信配置获取config* ...

  8. SpringBoot实现微信支付流程+RabbitMQ消息推送

    微信支付 整个流程使用到的组件代码: 链接:https://pan.baidu.com/s/1v5415tEtetxdsp4o7HMy5A 提取码:ys87 二维码创建 利用qrious制作二维码插件 ...

  9. vue3前端实现微信支付

    要在Vue3前端实现微信支付,你需要按照以下步骤进行操作: 在微信支付官网上注册一个商户号,并下载微信支付SDK. 在你的Vue3项目中安装微信支付的npm包,例如:npm install weixi ...

最新文章

  1. 生成对抗网络学习笔记4----GAN(Generative Adversarial Nets)的实现
  2. oracle RAC信息,Oracle 查看 RAC GI 版本信息
  3. rtos与linux软件开发,实时Linux和RTOS的基本特性及技术进行比较
  4. 闲鱼把各种玩法做成了一个平台:哆啦A梦
  5. Java多线程(三)之ConcurrentHashMap深入分析
  6. matlab运算速度与cpu的关系,请教编程语言和运算速度的关系
  7. python判断字符类型编程_Python检测数据类型的方法总结
  8. linux的可执行文件通常放在哪个目录中?写出该目录的路径.,实验2 Linux的基本操作与 使用vi编辑器 2010 (1)...
  9. JS中的六大数据类型 (笔记0)
  10. 使用采用 Android* OS 的英特尔® 集成性能基元
  11. 论文笔记-LSHTC: A Benchmark for Large-Scale Text Classification-2015
  12. PAT:1031. 查验身份证(15) AC
  13. HDOJ--2112--HDU Today
  14. 2019美赛C题论文解读
  15. 电子计算机主机房国标,中华人民共和国国家标准电子计算机机房设计规范GB50174-93...
  16. WhatsApp对话生成器使用教程
  17. sl4a最新版下载_SL4A Script Launcher
  18. cad化工设备绘图_auto cad在化工设备制图中的应用 ——致初学cad绘图者.ppt
  19. 数据库设计中面临的主要困难和问题的总结
  20. ubuntu18.04中基于Docker搭建tensorflow-gpu开发环境

热门文章

  1. 低代码、端到端,一小时构建IoT示例场景,声网发布灵隼物联网云平台
  2. TCP/IP编程之getsockopt/setsockopt函数详解
  3. 卡巴斯基实验室被独立研究机构评选为领导者
  4. 实体店防盗,RFID技术作用巨大
  5. 基于SpringBoot+VUE的线上教学管理平台系统
  6. jdbc连接orcle数据库_JDBC连接Oracle数据库简单步骤
  7. 中国石油大学《红楼梦研究》第一阶段在线作业
  8. 15 EXCEL仪表盘创建2
  9. 笔记:图解系统(小林coding)
  10. 嵌入式行业怎么样,有什么好的就业方向?