コード例 #1
0
ファイル: wx.cs プロジェクト: wanxb/mvc_demo
        //公众号 -  shengbanglvye
        //string AppID = "wx310c5048bf9e3618";
        //string AppSecret = "1ed9554708ce8a29e67c2c1cb30cacdd";


        #region 发送消息相关
        //发送模版信息--微OA任务提醒
        //提醒, 发普通消息和图文消息有限制,即 关注者和账号主题 一段时间没互动,就发不过去了,模版信息无此限制,
        //这里选用了 微oa 任务模版,其他模版类似,你可以选用其他模版适用不同场景,用法大同小异
        public retmsg SendMsg_mb_woarwtx(my_woa model)
        {
            //string userId = "ojkrJw7RqLdbJtTf0-p270D8bZQc", string title = "", string description = "", string url2 = ""
            //模版编号 OPENTM205196607
            retmsg ret = new retmsg();
            //wx_token.access_token = "";
            var access_token = getAccessToken();
            var url          = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
            var postObj      = new
            {
                touser = model.userId,
                //行信科技模板号
                template_id = "NYqQ_c5Dcw82tIOW9FvwcXPY8FPLC8QPhBrpX5H-ifI",
                //胜邦绿野模版号
                //template_id = "uY1JBpBqNoCNGL6N-Cv-nDtmRKgydvTA47w4nri5azE",
                url  = model.url2,
                data = new
                {
                    first = new
                    {
                        value = model.title,
                        color = "#173177"
                    },
                    keyword1 = new
                    {
                        value = model.rwmc,
                        color = "#173177"
                    },
                    keyword2 = new
                    {
                        value = model.xgry,
                        color = "#173177"
                    },
                    remark = new
                    {
                        value = model.description + " " + DateTime.Now.ToString("yyyy-MM-dd"),
                        color = "#173177"
                    }
                }
            };



            string rel    = RequestByPost("post", url, JsonConvert.SerializeObject(postObj));
            var    objRel = JsonConvert.DeserializeObject <SendMsgReturn>(rel);

            if (objRel.errcode == "0")
            {
                ret.flag = "ok";
                return(ret);
            }
            else
            {
                //记录错误日志  objRel.errcode    objRel.errmsg   objRel.msgid
                ret.flag    = "err";
                ret.message = "失败-" + objRel.errcode + objRel.errmsg + objRel.msgid;
                return(ret);
            }
        }
コード例 #2
0
        public string SendWXMes(string wxid, string title, string description, string rwmc, string xgry, string url)
        {
            my_woa wx = new my_woa();

            wx.userId      = wxid;
            wx.title       = title;
            wx.description = description;
            wx.rwmc        = rwmc;
            wx.xgry        = xgry;
            wx.url2        = url;
            retmsg ret = new Bll.wx.wx().SendMsg_mb_woarwtx(wx);

            if (ret.flag == "err")
            {
                return("error" + ret.message);
            }

            return("ok");
        }