|
|
|
@@ -54,6 +54,7 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
record.setCreateDate(new Date()); |
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
setQrcode(record); |
|
|
|
|
|
|
|
wxScreenAdMapper.insertSelective(record); |
|
|
|
@@ -92,42 +93,46 @@ 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_COUPON = "pages/coupon/detail/index"; |
|
|
|
private static String QRCODE_PAGE_CAMPGIN = "pages/bannerdetail/index"; |
|
|
|
private static String QRCODE_PAGE_HOME = "pages/index/index"; |
|
|
|
private static boolean QRCODE_AUTO_COLOR = false; |
|
|
|
//private static int QRCODE_LINCOLOR =; |
|
|
|
private static boolean QRCODE_IS_HYALINE = false; |
|
|
|
//private static int QRCODE_LINCOLOR =; |
|
|
|
|
|
|
|
private static String QRCODE_JUMP_CMD_HOME = "JH"; |
|
|
|
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<String,Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
map.put("scene", id.toString()); |
|
|
|
|
|
|
|
if (EnumScreenAdType.COUPON.getCode().equals(type)) |
|
|
|
map.put("page", QRCODE_PAGE_COUPON); |
|
|
|
map.put("scene", QRCODE_JUMP_CMD_COUPON+":"+id.toString()); |
|
|
|
else if (EnumScreenAdType.CAMPAIGN.getCode().equals(type)) |
|
|
|
map.put("page", QRCODE_PAGE_CAMPGIN); |
|
|
|
map.put("scene", QRCODE_JUMP_CMD_CAMPGIN+":"+id.toString()); |
|
|
|
else |
|
|
|
map.put("page", QRCODE_PAGE_HOME); |
|
|
|
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("line_color", ); |
|
|
|
map.put("is_hyaline", QRCODE_IS_HYALINE); |
|
|
|
//map.put("line_color", ); |
|
|
|
|
|
|
|
HttpEntity<Map<String,Object>> entity = new HttpEntity<Map<String,Object>>(map, headers); |
|
|
|
String reqUrl =wxacodeunlimit+accessToken; |
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(reqUrl, entity, byte[].class); |
|
|
|
|
|
|
|
byte[] result = null; |
|
|
|
if(responseEntity.hasBody()) { |
|
|
|
return responseEntity.getBody(); |
|
|
|
result = responseEntity.getBody(); |
|
|
|
} |
|
|
|
if (result[0]==0xff){ //image |
|
|
|
return result; |
|
|
|
} else { |
|
|
|
logger.error( "QRCODE get error:" + result.toString()); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|