• 脚本中发送消息,只能发送给系统用户

通过request对象的两个方法

    • public ObjTemplateMsg createWxMsg(String asTemplateId) 

创建消息对象

    • public int sendWxMsgUser(Long aUserId,ObjTemplateMsg aMsg) 

       发送消息给用户,返回发送的消息id,如果userid,为null,表示直接发送消息,消息中必须携带openid,

成功返回1 失败0 

    • public  int sendWxMsgWorkgroup(String asAppId,Long aWorkgroupID,ObjTemplateMsg aMsg) 

       发送消息给工作组,返回成功发送的用户数量

    • public int sendWxMsg(String asAppId,ObjTemplateMsg aMsg)

在消息中指定openid发送消息 ,成功返回1 失败0 


    

  • 微信模板消息对象



重要说明,模板消息中去掉了first和remark,微信会屏蔽掉。 

public class ObjTemplateMsg {

    public String touser; //openid 目标用户,这里可以忽略,若没有指定userid必须指定此属性

    public String template_id;//"ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY", 模板id 见微信公众号设置,必须提供

    public String url;//http://weixin.qq.com/download, 点击打开订单网页,可以为空

    public ObjMp  miniprogram = new ObjMp(); 点击代开的小程序信息,可以为空

    public String client_msg_id;//":"MSG_000001",//防重入id。对于同一个openid + client_msg_id, 可以为空

    public void addProp(String asKey,String asValue,String color) {   } //根据模板确定// 属性,值和颜色 

    public void addProp(String asKey,String asValue) { }//根据模板确定//属性,值 

}

public static class ObjMp {//小程序信息

        public String appid;//:打开小程序的id

        public String pagepath;//:"pages/index/index?foo=bar" 打开小程序的路径

}





  • 脚本发送模板消息举例


var lMsg = request.createWxMsg('FbmCzNo3vmV3GZ-U4gu-VdF_md8H6sBePxY_ZMM0G9Q');

lMsg.addProp('keyword1','key1')

lMsg.addProp('keyword2','key2')

lMsg.addProp('keyword3','key3')

lMsg.addProp('keyword4','key4')

lMsg.addProp('keyword5','key5')


request.sendWxMsgUser(request.parser().userid(),lMsg);

  • 工作流脚本中的消息通知
    1. 消息组件的脚本中使用    inst.users(); 获得消息关联的所有用户(包括消息发送的指定用户,工作组中的用户和动态用户)
    2. 使用request.sendWxMsgUser(String asAppId,Long aUserId,ObjTemplateMsg aMsg) 来发送消息  

 举例 :

var lMsg = request.createWxMsg('FbmCzNo3vmV3GZ-U4gu-VdF_md8H6sBePxY_ZMM0G9Q');

lMsg.addProp('first','首先说明')

lMsg.addProp('keyword1','关键词1')

lMsg.addProp('keyword2','关键词2')

lMsg.addProp('keyword3','key3')

lMsg.addProp('keyword4','key4')

lMsg.addProp('keyword5','key5')

lMsg.addProp('remark','备注说明这里是')

request.sendWxMsgUser("wx57e64f27146325ed",inst.users(),lMsg);



Created with the Personal Edition of HelpNDoc: Free EPub producer