
小程序生成二维码
-
2023年2月19日发(作者:)微信⼩程序⽣成带参数的⼆维码java_⽣成微信⼩程序码java实
现
@OverridepublicModelAndViewonSubmit(HttpServletRequestreq,HttpServletResponseres,WxQrCodeFormcmd,
BindExceptionerr)throwsException{
SimpleResultresult=(false);
Localelocale=newLocale(\"en\",\"US\");
ResourceBundleresource=dle(\"config/wx-config\",locale);//读取属性⽂件
StringappId=ing(\"appId\");//开发者设置中的appId
Stringsecret=ing(\"appSecret\");//开发者设置中的appSecret
AccessTokenaccessToken=null;
StringrequestUrl=\"/cgi-bin/token?grant_type=client_credential&appid=\"+appId+\"&secret=\"
+secret;
JSONObjectjsonObject=quest(requestUrl,\"GET\",null);//如果请求成功
if(null!=jsonObject){try{
accessToken=newAccessToken();
en(ing(\"access_token\"));
iresIn(Value(\"expires_in\"));
}catch(JSONExceptione){
accessToken=null;//获取token失败
(\"获取token失败errcode:{}errmsg:{}\",Value(\"errcode\"),ing(\"errmsg\"));
}
}
Stringtoken=en();
getminiqrQr(token);(result);
}publicMapgetminiqrQr(StringaccessToken){
RestTemplaterest=newRestTemplate();
InputStreaminputStream=null;
OutputStreamoutputStream=null;try{
Stringurl=\"/weixin/getwxacode?access_token=\"+accessToken;
Mapparam=newHashMap();
(\"path\",\"pages/search/search\");//跳转到查询物流(⾃定义)
(\"width\",430);
(\"auto_color\",false);
Mapline_color=newHashMap();
line_(\"r\",0);
line_(\"g\",0);
line_(\"b\",0);
(\"line_color\",line_color);
(\"调⽤⽣成微信URL接⼝传参:\"+param);
MultiValueMapheaders=newLinkedMultiValueMap();
HttpEntityrequestEntity=newHttpEntity(String(param),headers);
ResponseEntityentity=ge(url,,requestEntity,byte[].class,newObject[0]);
(\"调⽤⼩程序⽣成微信永久⼩程序码URL接⼝返回结果:\"+y());byte[]result=y();
(Base64String(result));
inputStream=newByteArrayInputStream(result);
Filefile=newFile(\"/Users/apple/Desktop/\");if(!()){
NewFile();
}
outputStream=newFileOutputStream(file);intlen=0;byte[]buf=newbyte[1024];while((len=(buf,0,
1024))!=-1){
(buf,0,len);
}
();
}catch(Exceptione){
(\"调⽤⼩程序⽣成微信永久⼩程序码URL接⼝异常\",e);
}finally{if(inputStream!=null){try{
();
}catch(IOExceptione){
tackTrace();
}
}if(outputStream!=null){try{
();
}catch(IOExceptione){
tackTrace();
}
}
}returnnull;
}