微信消息初始化,日志打印增加
This commit is contained in:
parent
acf2e56ffc
commit
e2f5b6031a
@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -34,8 +35,8 @@ import java.util.Map;
|
|||||||
* @author Chopper
|
* @author Chopper
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
|
||||||
public class WechatMPMessageServiceImpl extends ServiceImpl<WechatMPMessageMapper, WechatMPMessage> implements WechatMPMessageService {
|
public class WechatMPMessageServiceImpl extends ServiceImpl<WechatMPMessageMapper, WechatMPMessage> implements WechatMPMessageService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private WechatAccessTokenUtil wechatAccessTokenUtil;
|
private WechatAccessTokenUtil wechatAccessTokenUtil;
|
||||||
@ -52,6 +53,9 @@ public class WechatMPMessageServiceImpl extends ServiceImpl<WechatMPMessageMappe
|
|||||||
* post 删除模版 添加模版 获取模版id
|
* post 删除模版 添加模版 获取模版id
|
||||||
*/
|
*/
|
||||||
private final String delMsgTpl = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=";
|
private final String delMsgTpl = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=";
|
||||||
|
/**
|
||||||
|
* post 添加模版
|
||||||
|
*/
|
||||||
private final String addTpl = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=";
|
private final String addTpl = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,6 +65,8 @@ public class WechatMPMessageServiceImpl extends ServiceImpl<WechatMPMessageMappe
|
|||||||
String accessToken = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
String accessToken = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||||
//获取已有模版,删除
|
//获取已有模版,删除
|
||||||
String context = HttpUtil.get(allMsgTpl + accessToken);
|
String context = HttpUtil.get(allMsgTpl + accessToken);
|
||||||
|
|
||||||
|
log.info("获取全部模版:{}", context);
|
||||||
JSONObject jsonObject = new JSONObject(context);
|
JSONObject jsonObject = new JSONObject(context);
|
||||||
WechatMessageUtil.wechatHandler(jsonObject);
|
WechatMessageUtil.wechatHandler(jsonObject);
|
||||||
List<String> oldList = new ArrayList<>();
|
List<String> oldList = new ArrayList<>();
|
||||||
@ -73,7 +79,8 @@ public class WechatMPMessageServiceImpl extends ServiceImpl<WechatMPMessageMappe
|
|||||||
oldList.forEach(templateId -> {
|
oldList.forEach(templateId -> {
|
||||||
Map<String, Object> params = new HashMap<>(1);
|
Map<String, Object> params = new HashMap<>(1);
|
||||||
params.put("priTmplId", templateId);
|
params.put("priTmplId", templateId);
|
||||||
WechatMessageUtil.wechatHandler(HttpUtil.post(delMsgTpl + accessToken, params));
|
String message = WechatMessageUtil.wechatHandler(HttpUtil.post(delMsgTpl + accessToken, params));
|
||||||
|
log.info("删除模版响应:{}", message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +96,7 @@ public class WechatMPMessageServiceImpl extends ServiceImpl<WechatMPMessageMappe
|
|||||||
JSONArray jsonArray = new JSONObject(keywordsItems).getJSONArray("data");
|
JSONArray jsonArray = new JSONObject(keywordsItems).getJSONArray("data");
|
||||||
List<WechatMessageKeyword> keywordArray = jsonArray.toList(WechatMessageKeyword.class);
|
List<WechatMessageKeyword> keywordArray = jsonArray.toList(WechatMessageKeyword.class);
|
||||||
|
|
||||||
log.error("keywords:" + keywordArray);
|
log.info("keywords:" + keywordArray);
|
||||||
//存放约定好的kids
|
//存放约定好的kids
|
||||||
List<String> kids = new ArrayList<>(tplData.keyWord.size());
|
List<String> kids = new ArrayList<>(tplData.keyWord.size());
|
||||||
List<String> kidTexts = new ArrayList<>(tplData.keyWord.size());
|
List<String> kidTexts = new ArrayList<>(tplData.keyWord.size());
|
||||||
@ -110,8 +117,9 @@ public class WechatMPMessageServiceImpl extends ServiceImpl<WechatMPMessageMappe
|
|||||||
params.put("tid", tplData.getTid());
|
params.put("tid", tplData.getTid());
|
||||||
params.put("kidList", kids);
|
params.put("kidList", kids);
|
||||||
params.put("sceneDesc", tplData.getSceneDesc());
|
params.put("sceneDesc", tplData.getSceneDesc());
|
||||||
|
log.info("添加模版参数:{}", JSONUtil.toJsonStr(params));
|
||||||
String content = HttpUtils.doPostWithJson(addTpl + accessToken, params);
|
String content = HttpUtils.doPostWithJson(addTpl + accessToken, params);
|
||||||
log.error(JSONUtil.toJsonStr(params));
|
log.info("添加模版响应:{}", content);
|
||||||
JSONObject tplContent = new JSONObject(content);
|
JSONObject tplContent = new JSONObject(content);
|
||||||
WechatMessageUtil.wechatHandler(tplContent);
|
WechatMessageUtil.wechatHandler(tplContent);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -33,6 +34,7 @@ import java.util.Map;
|
|||||||
* @author Chopper
|
* @author Chopper
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public class WechatMessageServiceImpl extends ServiceImpl<WechatMessageMapper, WechatMessage> implements WechatMessageService {
|
public class WechatMessageServiceImpl extends ServiceImpl<WechatMessageMapper, WechatMessage> implements WechatMessageService {
|
||||||
|
|
||||||
@ -51,6 +53,9 @@ public class WechatMessageServiceImpl extends ServiceImpl<WechatMessageMapper, W
|
|||||||
* post 删除模版 添加模版 获取模版id
|
* post 删除模版 添加模版 获取模版id
|
||||||
*/
|
*/
|
||||||
private final String delMsgTpl = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=";
|
private final String delMsgTpl = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=";
|
||||||
|
/**
|
||||||
|
* post 添加模版
|
||||||
|
*/
|
||||||
private final String addTpl = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=";
|
private final String addTpl = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,9 +75,13 @@ public class WechatMessageServiceImpl extends ServiceImpl<WechatMessageMapper, W
|
|||||||
setIndustryParams.put("industry_id2", 5);
|
setIndustryParams.put("industry_id2", 5);
|
||||||
String context = HttpUtils.doPostWithJson(setIndustry + accessToken, setIndustryParams);
|
String context = HttpUtils.doPostWithJson(setIndustry + accessToken, setIndustryParams);
|
||||||
|
|
||||||
|
log.info("设置行业:{}", context);
|
||||||
//获取已有模版,删除
|
//获取已有模版,删除
|
||||||
context = HttpUtil.get(allMsgTpl + accessToken);
|
context = HttpUtil.get(allMsgTpl + accessToken);
|
||||||
JSONObject jsonObject = new JSONObject(context);
|
JSONObject jsonObject = new JSONObject(context);
|
||||||
|
|
||||||
|
|
||||||
|
log.info("获取全部模版:{}", context);
|
||||||
WechatMessageUtil.wechatHandler(jsonObject);
|
WechatMessageUtil.wechatHandler(jsonObject);
|
||||||
List<String> oldList = new ArrayList<>();
|
List<String> oldList = new ArrayList<>();
|
||||||
if (jsonObject.containsKey("template_list")) {
|
if (jsonObject.containsKey("template_list")) {
|
||||||
@ -84,7 +93,8 @@ public class WechatMessageServiceImpl extends ServiceImpl<WechatMessageMapper, W
|
|||||||
oldList.forEach(templateId -> {
|
oldList.forEach(templateId -> {
|
||||||
Map<String, Object> params = new HashMap<>(1);
|
Map<String, Object> params = new HashMap<>(1);
|
||||||
params.put("template_id", templateId);
|
params.put("template_id", templateId);
|
||||||
WechatMessageUtil.wechatHandler(HttpUtil.post(delMsgTpl + accessToken, params));
|
String message = WechatMessageUtil.wechatHandler(HttpUtil.post(delMsgTpl + accessToken, params));
|
||||||
|
log.info("删除模版响应:{}", message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +105,8 @@ public class WechatMessageServiceImpl extends ServiceImpl<WechatMessageMapper, W
|
|||||||
Map<String, Object> params = new HashMap<>(1);
|
Map<String, Object> params = new HashMap<>(1);
|
||||||
params.put("template_id_short", tplData.getMsgId());
|
params.put("template_id_short", tplData.getMsgId());
|
||||||
String content = HttpUtils.doPostWithJson(addTpl + accessToken, params);
|
String content = HttpUtils.doPostWithJson(addTpl + accessToken, params);
|
||||||
|
log.info("添加模版响应:{}", content);
|
||||||
|
|
||||||
JSONObject tplContent = new JSONObject(content);
|
JSONObject tplContent = new JSONObject(content);
|
||||||
WechatMessageUtil.wechatHandler(tplContent);
|
WechatMessageUtil.wechatHandler(tplContent);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user