小程序
小游戏
企业微信
微信支付
扫描小程序码分享
微信小程序如何生成二维码?有经验的同学们,能分享一下吗?需要贴代码
4 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你发送的流数据是请求到的那段乱码(二进制数据)吗还是base64编码过的?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
String URL = "二维码接口地址"; String meetingId=request.getParameter("id");//我自己的参数,不用管 log.info("------------------createwxaqrcode"+meetingId); if(meetingId!=null&&meetingId.trim().length()>0){ String access_token; InputStream is=null; OutputStream os=null; try { access_token = getAccess_token();//获取token,我自己写的方法,把acess_token获取出来就行 URL = URL + "?access_token=" + access_token; Map<String, Object> map = new HashMap<String, Object>(); map.put("path", "pages/index/index?meetingId="+meetingId); map.put("width", 375); JSONObject json = new JSONObject(map); CloseableHttpClient client = HttpClients.createDefault(); HttpPost post = new HttpPost(URL); post.addHeader(HTTP.CONTENT_TYPE, "application/json"); StringEntity se; se = new StringEntity(json.toString()); se.setContentType("application/json"); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "UTF-8")); post.setEntity(se); StringEntity s = new StringEntity(json.toString(), "utf-8"); s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(s); HttpResponse res = client.execute(post); if(res!=null){ HttpEntity resEntity = res.getEntity(); if (resEntity != null) { // 获取响应输入流 is = resEntity.getContent(); response.setHeader("Content-Type","application/x-msdownload"); os=response.getOutputStream(); //os=new FileOutputStream("D:\\test.png");//生成图片 int count = 0; byte[] buffer = new byte[1024 * 8]; while ((count = is.read(buffer)) != -1) { os.write(buffer, 0, count); os.flush(); } os.close(); is.close(); } }
我是直接把流发送到小程序端的,直接用image标签的 src属性读取的
请问小程序怎么从后台获取本程序的页面二维码?
通过微信小程序二维码接口获取了一大串二进制,编码传到后台后,生成的图片打不开,请问是怎么回事?
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你发送的流数据是请求到的那段乱码(二进制数据)吗还是base64编码过的?
String URL = "二维码接口地址";
String meetingId=request.getParameter("id");//我自己的参数,不用管
log.info("------------------createwxaqrcode"+meetingId);
if(meetingId!=null&&meetingId.trim().length()>0){
String access_token;
InputStream is=null;
OutputStream os=null;
try {
access_token = getAccess_token();//获取token,我自己写的方法,把acess_token获取出来就行
URL = URL + "?access_token=" + access_token;
Map<String, Object> map = new HashMap<String, Object>();
map.put("path", "pages/index/index?meetingId="+meetingId);
map.put("width", 375);
JSONObject json = new JSONObject(map);
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(URL);
post.addHeader(HTTP.CONTENT_TYPE, "application/json");
StringEntity se;
se = new StringEntity(json.toString());
se.setContentType("application/json");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "UTF-8"));
post.setEntity(se);
StringEntity s = new StringEntity(json.toString(), "utf-8");
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
post.setEntity(s);
HttpResponse res = client.execute(post);
if(res!=null){
HttpEntity resEntity = res.getEntity();
if (resEntity != null) {
// 获取响应输入流
is = resEntity.getContent();
response.setHeader("Content-Type","application/x-msdownload");
os=response.getOutputStream();
//os=new FileOutputStream("D:\\test.png");//生成图片
int count = 0;
byte[] buffer = new byte[1024 * 8];
while ((count = is.read(buffer)) != -1) {
os.write(buffer, 0, count);
os.flush();
}
os.close();
is.close();
}
}
我是直接把流发送到小程序端的,直接用image标签的 src属性读取的
请问小程序怎么从后台获取本程序的页面二维码?
通过微信小程序二维码接口获取了一大串二进制,编码传到后台后,生成的图片打不开,请问是怎么回事?