收藏
回答

ios消息模板推送问题

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug templateMessage.send 客户端 7.0.3 2.6.6

- 当前 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("/publishModelMessage")
public String publishModelMessage(@LoginUser UserVo loginUser,@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 CommonUtil 
public 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;
}
}



回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员-灵芝
    社区技术运营专员-灵芝
    2019-05-21

    麻烦提供一下信息:

    1.appid、openID、formid
    2.最近一次操作时间(特别说明,5小时内才有机会快速定位)
    3.发送的请求
    4.收到的回复消息
    5.此是否必现呢?

    另外,是否设置了拒收模板消息?

    2019-05-21
    赞同
    回复 3
    • 王少雄
      王少雄
      2019-05-21

      wx342e88ad034ff543

      ol6sv5bV_isrkKTuAckMp2JQBL60

      768b77f40fa14342912b0e1e6a95eafb

      2019-05-21 15:16:37

      POST

      {"errcode":0,"errmsg":"ok"}

      必现

      没有设置拒收






      2019-05-21
      回复
    • 社区技术运营专员-灵芝
      社区技术运营专员-灵芝
      2019-05-21回复王少雄

      post的数据是什么?

      2019-05-21
      回复
    • 王少雄
      王少雄
      2019-05-21回复社区技术运营专员-灵芝

      {"keyword5":{"color":"#ffffff","value":"具体余额请查看详情"},"keyword3":{"color":"#ffffff","value":"返佣收益"},"keyword4":{"color":"#ffffff","value":"Tue May 21 17:16:41 CST 2019"},"keyword1":{"color":"#ffffff","value":"小明"},"keyword2":{"color":"#ffffff","value":"10000元"}}

      2019-05-21
      回复
登录 后发表内容