diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java index da2c7aa01..97a156407 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java @@ -1,8 +1,6 @@ package com.iformall.service.impl; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import cn.binarywang.wx.miniapp.api.WxMaService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; @@ -19,22 +17,16 @@ import com.iformall.mapper.WxCampaignMapper; import com.iformall.mapper.WxCouponChannelMapper; import com.iformall.mapper.WxScreenAdMapper; import com.iformall.service.WxAppinfoService; -import com.iformall.service.WxCampaignService; import com.iformall.service.WxScreenAdService; +import com.iformall.utils.MaUtil; +import me.chanjar.weixin.common.error.WxErrorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; @Service public class WxScreenAdServiceImpl implements WxScreenAdService { @@ -157,8 +149,6 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { } } - private static String wxacodeunlimit = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="; - private static int QRCODE_WIDTH = 300; private static String QRCODE_PAGE_HOME = "pages/index/index"; private static boolean QRCODE_AUTO_COLOR = false; @@ -169,44 +159,25 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { private static String QRCODE_JUMP_CMD_COUPON = "JC"; private static String QRCODE_JUMP_CMD_CAMPGIN = "JB"; private byte[] getQrcode(Long id, int type, WxAppinfo appInfo) throws Exception { - String accessToken = appInfo.getAccessToken(); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - Map map = new HashMap<>(); + if(appInfo == null) { + logger.error("QRCODE get error: appinfo is null"); + return null; + } + WxMaService wxMaService = MaUtil.getWeappService(appInfo); + String scene = ""; if (EnumScreenAdType.COUPON.getCode().equals(type)) - map.put("scene", QRCODE_JUMP_CMD_COUPON+":"+id.toString()); + scene = QRCODE_JUMP_CMD_COUPON+":"+id.toString(); else if (EnumScreenAdType.CAMPAIGN.getCode().equals(type)) - map.put("scene", QRCODE_JUMP_CMD_CAMPGIN+":"+id.toString()); + scene = QRCODE_JUMP_CMD_CAMPGIN+":"+id.toString(); else - map.put("scene", QRCODE_JUMP_CMD_HOME+":"+"0"); - - map.put("page", QRCODE_PAGE_HOME); - map.put("width", QRCODE_WIDTH); - map.put("auto_color", QRCODE_AUTO_COLOR); - map.put("is_hyaline", QRCODE_IS_HYALINE); - //map.put("line_color", ); - - HttpEntity> entity = new HttpEntity>(map, headers); - String reqUrl =wxacodeunlimit+accessToken; - - RestTemplate restTemplate = new RestTemplate(); - ResponseEntity responseEntity = restTemplate.postForEntity(reqUrl, entity, byte[].class); - byte[] result = null; - if(responseEntity.hasBody()) { - result = responseEntity.getBody(); - try { - JSONObject jResult = JSONObject.parseObject(result.toString()); - if (jResult != null) { //error - logger.error( "QRCODE get error:" + jResult.getIntValue("errcode")+"-"+ jResult.getString("errmsg")); - return null; - } - } catch (Exception e) { - return result; - } - } + scene = QRCODE_JUMP_CMD_HOME+":"+"0"; - logger.error( "QRCODE get error responseEntity:" + responseEntity.toString()); + try { + return wxMaService.getQrcodeService().createWxaCodeUnlimitBytes(scene, QRCODE_PAGE_HOME, QRCODE_WIDTH, QRCODE_AUTO_COLOR, null, QRCODE_IS_HYALINE); + }catch (WxErrorException e) { + logger.error("QRCODE get error: " + e.getMessage()); + } return null; } }