ios消息模板推送问题
- 当前 Bug 的表现(可附上截图)
- 预期表现
安卓机能收到推送消息
ios同样发送成功没有收到推送消息
- 复现路径
- 提供一个最简复现 Demo
<form bind:submit=“testSubmit” report-submit=“true”>
<button formType=“submit” class=‘modelButton’>发送模板消息</button>
</form>
Page({
testSubmit: function (e) {
console.log(e);
wx.request({
url: ‘******/api/message/publishModelMessage’,
header: {
“Content-Type”: “application/json”
},
method: “GET”,
data: { “formId”: e.detail.formId },
success: function (res) {
console.log(“res”,res)
}
})
}
})
[@GetMapping](/user/GetMapping)("/publishModelMessage")
public String publishModelMessage([@LoginUser](/user/LoginUser) UserVo loginUser,[@RequestParam](/user/RequestParam)(required = false) String formId, HttpServletResponse response) throws IOException {
String accessToken = WXUtils.getAccessToken();
WxMssVo wxMssVo = new WxMssVo();
wxMssVo.setTemplate_id("**********");
wxMssVo.setTouser("***********");
wxMssVo.setAccess_token("********");
wxMssVo.setPage("pages/index/index");
wxMssVo.setRequest_url("https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=
********";
wxMssVo.setForm_id(formId);
List<TemplateData> list = new ArrayList<>();
list.add(new TemplateData("小明","#ffffff"));
list.add(new TemplateData("10000元","#ffffff"));
list.add(new TemplateData("返佣收益","#ffffff"));
list.add(new TemplateData(new Date().toString(),"#ffffff"));
list.add(new TemplateData("具体余额请查看详情","#ffffff"));
wxMssVo.setParams(list);
System.out.println(wxMssVo.toString());
CommonUtil.sendTemplateMessage(wxMssVo);
return null;}
//发送模板消息class CommonUtilpublic static String sendTemplateMessage(WxMssVo wxMssVo) {
String info = "";
try {
//创建连接
URL url = new URL(wxMssVo.getRequest_url());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Type", "utf-8");
connection.connect();
//POST请求
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
JSONObject obj = new JSONObject();
obj.put("access_token", wxMssVo.getAccess_token());
obj.put("touser", wxMssVo.getTouser());
obj.put("template_id", wxMssVo.getTemplate_id());
obj.put("form_id", wxMssVo.getForm_id());
obj.put("page", wxMssVo.getPage());
JSONObject jsonObject = new JSONObject();
for (int i = 0; i < wxMssVo.getParams().size(); i++) {
JSONObject dataInfo = new JSONObject();
dataInfo.put("value", wxMssVo.getParams().get(i).getValue());
dataInfo.put("color", wxMssVo.getParams().get(i).getColor());
jsonObject.put("keyword" + (i + 1), dataInfo);
}
obj.put("data", jsonObject);
out.write(obj.toString().getBytes());
out.flush();
out.close();
//读取响应
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String lines;
StringBuffer sb = new StringBuffer("");
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "utf-8");
sb.append(lines);
}
info = sb.toString();
System.out.println(sb);
reader.close();
// 断开连接
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return info;
}
用到的实体
public class WxMssVo {
private String touser;
private String template_id;
private String page;
private String form_id;
private String access_token;
private String request_url;
private List<TemplateData> params = new ArrayList<TemplateData>();
public void setTouser(String touser) {
this.touser = touser;
}
public void setTemplate_id(String template_id) {
this.template_id = template_id;
}
public void setPage(String page) {
this.page = page;
}
public void setForm_id(String form_id) {
this.form_id = form_id;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public void setRequest_url(String request_url) {
this.request_url = request_url;
}
public void setParams(List<TemplateData> params) {
this.params = params;
}
public String getTouser() {
return touser;
}
public String getTemplate_id() {
return template_id;
}
public String getPage() {
return page;
}
public String getForm_id() {
return form_id;
}
public String getAccess_token() {
return access_token;
}
public String getRequest_url() {
return request_url;
}
public List<TemplateData> getParams() {
return params;
}}
public class TemplateData {
private String key;
private String value;
private String color;
public TemplateData(String value, String color) {
this.value = value;
this.color = color;
}
public void setKey(String key) {
this.key = key;
}
public void setValue(String value) {
this.value = value;
}
public void setColor(String color) {
this.color = color;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public String getColor() {
return color;
}
}