微信二维码支付流程
API接口
?
?
調用API接口Controller
模擬二維碼代碼:
package com.bjsxt.code;import com.alibaba.fastjson.JSONObject; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import org.junit.Test;import java.io.IOException; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; import java.util.HashMap; import java.util.Map;public class QR_Code {@Testpublic void qrCodeGenerator() throws Exception {//生成二維碼//定義json字符串,使用fastjsonJSONObject jsonObj=new JSONObject();//給jsonobj存放數據jsonObj.put("name","lht");jsonObj.put("age","22");jsonObj.put("place","XJ");//將jsonobj轉化為字符串String jsonString = jsonObj.toJSONString();int height=200;int wight=200;Map<EncodeHintType,Object> map=new HashMap<>();//指定字符集map.put(EncodeHintType.CHARACTER_SET,"UTF-8");//創建一個矩陣對象BitMatrix bitMatrix=new MultiFormatWriter().encode(jsonString, BarcodeFormat.QR_CODE,wight,height,map);Path path= FileSystems.getDefault().getPath("D://","QR_CODE.jpg");//根據矩陣生成圖片MatrixToImageWriter.writeToPath(bitMatrix,"jpg",path);System.out.println("二維碼生成成功");} }?
總結
- 上一篇: 三星Galaxy S4(I9500、I9
- 下一篇: clc和clear命令的使用