|
@@ -209,6 +209,81 @@ public class UserServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public byte[] getCouponQRCodePng(ToolWxConfig conf, String key, String redisKey) {
|
|
|
+ String token = getWxAccessToken(conf);
|
|
|
+
|
|
|
+ Map<String, Object> resultObj = new HashMap();
|
|
|
+ PrintWriter out = null;
|
|
|
+ InputStream in = null;
|
|
|
+ String result = "";
|
|
|
+ try {
|
|
|
+ URL realUrl = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token);
|
|
|
+ // 打开和URL之间的连接
|
|
|
+ URLConnection conn = realUrl.openConnection();
|
|
|
+ // 设置通用的请求属性
|
|
|
+ conn.setRequestProperty("accept", "*/*");
|
|
|
+ conn.setRequestProperty("connection", "Keep-Alive");
|
|
|
+ conn.setRequestProperty("user-agent",
|
|
|
+ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
+ // 发送POST请求必须设置如下两行
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ // 获取URLConnection对象对应的输出流
|
|
|
+ out = new PrintWriter(conn.getOutputStream());
|
|
|
+ // 发送请求参数
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("scene", key + "=" + redisKey); //参数自定义
|
|
|
+ jsonObject.put("page","pages/index/index");//要生成小程序码的链接
|
|
|
+ jsonObject.put("width",500);
|
|
|
+ jsonObject.put("env_version", conf.getEnvVersion());
|
|
|
+ out.print(jsonObject);
|
|
|
+ // flush输出流的缓冲
|
|
|
+ out.flush();
|
|
|
+ in = conn.getInputStream();
|
|
|
+ byte[] data = null;
|
|
|
+ // 读取图片字节数组
|
|
|
+ try {
|
|
|
+ ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
|
|
|
+ byte[] buff = new byte[100];
|
|
|
+ int rc = 0;
|
|
|
+ while ((rc = in.read(buff, 0, 100)) > 0) {
|
|
|
+ swapStream.write(buff, 0, rc);
|
|
|
+ }
|
|
|
+ data = swapStream.toByteArray();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("获取领券二维码出错",e);
|
|
|
+ } finally {
|
|
|
+ if (in != null) {
|
|
|
+ try {
|
|
|
+ in.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("获取领券二维码出错",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("发送 POST 请求出现异常!" + e);
|
|
|
+ log.error("发送 POST 请求出现异常!",e);
|
|
|
+ }
|
|
|
+ // 使用finally块来关闭输出流、输入流
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+ if (out != null) {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if (in != null) {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ } catch (IOException ex) {
|
|
|
+ log.error("关闭输出流、输入流!",ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// resultObj.put("result",result);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public UserInfo getMyInfo(UserParam userParam){
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
userInfo.setId("1");
|