首页 技术 正文
技术 2022年11月15日
0 收藏 420 点赞 4,724 浏览 1770 个字
  1. tip:通过该接口,仅能生成已发布的小程序的二维码。
  2. tip:可以在开发者工具预览时生成开发版的带参二维码。
  3. tip:接口A加上接口C,总共生成的码数量限制为100,000,请谨慎调用。
  4. tip: POST 参数需要转成 json 字符串,不支持 form 表单提交。
  5. tip: auto_color line_color 参数仅对小程序码生效。
    /*
* 获取二维码
   * 这里的 post 方法 为 json post【重点】
*/
@RequestMapping("/getCode")
public ResponseMsg getCodeM(HttpServletRequest request) throws Exception { String imei ="867186032552993";
String page="page/msg_waist/msg_waist";
String token = getToken(); // 得到token Map<String, Object> params = new HashMap<>();
params.put("scene", imei); //参数
params.put("page", "page/msg_waist/msg_waist"); //位置
params.put("width", 430); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpPost httpPost = new HttpPost("https://img.zhankr.net/q1ex0op2gxj182669";
saveToImgByInputStream(inputStream,"D:\\",name); //保存图片
return null;
} /*
* 获取 token
   * 普通的 get 可获 token
*/
public String getToken() {
try { Map<String, String> map = new LinkedHashMap<String, String>();
map.put("grant_type", grant_type);
map.put("appid", appid);
map.put("secret", secret); String rt = HttpUtils.sendGet(TOKEN_URL, map); System.out.println(rt);
JSONObject json = JSONObject.parseObject(rt); if (json.getString("access_token") != null || json.getString("access_token") != "") {
return json.getString("access_token");
} else {
return null;
}
} catch (Exception e) {
log.error("# 获取 token 出错... e:" + e);
e.printStackTrace();
return null;
} } /**
* 将二进制转换成文件保存
* @param instreams 二进制流
* @param imgPath 图片的保存路径
* @param imgName 图片的名称
* @return
* 1:保存正常
* 0:保存失败
*/
public static int saveToImgByInputStream(InputStream instreams,String imgPath,String imgName){
int stateInt = 1;
if(instreams != null){
try {
File file=new File(imgPath,imgName);//可以是任何图片格式.jpg,.png等
FileOutputStream fos=new FileOutputStream(file);
byte[] b = new byte[1024];
int nRead = 0;
while ((nRead = instreams.read(b)) != -1) {
fos.write(b, 0, nRead);
}
fos.flush();
fos.close();
} catch (Exception e) {
stateInt = 0;
e.printStackTrace();
} finally {
}
}
return stateInt;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,498
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,911
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,745
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,501
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,139
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,303