代码改变世界

微信支付

2019-07-22 20:14  后叶  阅读(116)  评论(0)    收藏  举报

支付功能

电商项目有很多特点,但是支付绝对非常必要的条件。没有支付功能的项目不可称为电商项目。 对于目前市面上电商项目占绝大多数的情况下,学习支付功能是有一定的竞争优势的。

微信支付

支付场景分两种:
1、手机APP支付
2、电脑网站支付

涉及到内网穿透:natapp

流程:
1、下载微信的SDK。
    a、可以官网上下载SDK
    b、可以maven导入。
2、继承WXPayConfig类,配置账号信息
3、实现IWXPayDomain接口,配置支付的域名。
4、下单。
    a、在自己系统中下单
    b、再在微信系统中下单。
    c、生成二维码。

image

Zxing二维码生成

1、导包

<!-- https://mvnrepository.com/artifact/com.google.zxing/core -->
    <dependency>
      <groupId>com.google.zxing</groupId>
      <artifactId>core</artifactId>
      <version>3.3.3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.zxing/javase -->
    <dependency>
      <groupId>com.google.zxing</groupId>
      <artifactId>javase</artifactId>
      <version>3.3.3</version>
    </dependency>

2、生成二维码

 @RequestMapping("/qrcode")
    public void qrcode(HttpServletResponse response) throws URISyntaxException, IOException {
        //二维码需要包含的文本内容
        String uri = "http://www.baidu.com";
        HashMap<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
        hints.put(EncodeHintType.MARGIN, 2);
        try {
            BitMatrix bitMatrix = new MultiFormatWriter().encode(uri, BarcodeFormat.QR_CODE, 200, 200, hints);
            MatrixToImageWriter.writeToStream(bitMatrix, "PNG", response.getOutputStream());
            System.out.println("创建二维码完成");
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

Goeasy实现异步支付结果

http://www.goeasy.io/