@RequestMapping("createMySmallCode")
@ResponseBody
public static String createMySmallCode(Long shopId, HttpServletRequest request) {
Result result = null;
String path = null;
String returnPath = null;
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + WeiXinPayConfig.xcx_appid + "&secret=" + WeiXinPayConfig.xcx_secret;
Map<String, String> resMap = new HashMap<>();
try {
String resultStr = HttpClientUtil.doGet(url, resMap);
Map<String, String> map = JsonMapUtil.jsonToMap(resultStr);
String accessToken = map.get("access_token");
String urlC = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
Map<String, Object> param = new HashMap();
param.put("width", 420);
param.put("scene", shopId);
param.put("page", "/pages/pay/pay");
MultiValueMap<String, String> headers = new LinkedMultiValueMap();
RestTemplate rest = new RestTemplate();
HttpEntity requestEntity = new HttpEntity(param, headers);
ResponseEntity entity = rest.exchange(urlC, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
byte[] data = (byte[]) entity.getBody();
String filepath = "/home/sys/upload/shopCode/file/";
File file = new File(filepath);
if (!file.exists()) {
file.mkdirs();
}
long currtime = System.currentTimeMillis();
path = filepath + currtime + ".jpg";
returnPath = currtime + ".jpg";
FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));
imageOutput.write(data, 0, data.length);
imageOutput.close();
} catch (Exception var23) {
var23.printStackTrace();
}
return request.getContextPath() + path;
}