Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (null == Session["strSiteName"] || null == Session["strSiteCode"] || null == Session["strLoginName"])
            {
                Response.Write("<script language=JavaScript>;parent.location.href='../Index.aspx';</script>");
                Response.End();
            }

            if (keyword.Text.Trim() != null && keyword.Text.Trim() != "")
            {
                WXConfigDAL    configdal  = new WXConfigDAL();
                DataSet        wxconfigds = configdal.GetWXConfigDataList(Session["strSiteCode"].ToString());
                MsgAutoRule    model      = new MsgAutoRule();
                MsgAutoRuleDAL dal        = new MsgAutoRuleDAL();
                model.MatchPattern = keyword.Text;
                model.Order        = Convert.ToInt32(sort.Text);
                model.MsgValue     = repmsgcontent.Value;
                model.ID           = Guid.NewGuid().ToString("N").ToUpper();
                model.Enabled      = 1;
                model.LastModTime  = DateTime.Now;
                model.MatchType    = "keywords";
                model.MsgType      = "text";
                if (wxconfigds != null && wxconfigds.Tables.Count > 0 && wxconfigds.Tables[0].Rows.Count > 0)
                {
                    model.WXConfigID = wxconfigds.Tables[0].Rows[0]["ID"].ToString();
                }
                model.Handle = "Mozart.WeiXin.SubscribeCouponActHandle";
                if (dal.AddMsgAutoRule(model))
                {
                    MessageBox.Show(this, "操作成功!");
                }
                else
                {
                    MessageBox.Show(this, "操作失败!");
                }
            }
            else
            {
                MessageBox.Show(this, "请输入信息名称后再操作!");
            }
        }
Exemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (null == Session["strSiteName"] || null == Session["strSiteCode"] || null == Session["strLoginName"])
            {
                Response.Write("<script language=JavaScript>;parent.location.href='../Index.aspx';</script>");
                Response.End();
            }

            if (!string.IsNullOrEmpty(keyword.Text.Trim()) &&
                fudVoice.HasFile &&
                fudVoice.PostedFile.ContentLength <= 1024 * 1024 * 2 &&
                (fudVoice.PostedFile.FileName.ToLower().Contains(".mp3") || fudVoice.PostedFile.FileName.ToLower().Contains(".amr")))
            {//语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
                try
                {
                    //先上传并插入微信媒体表
                    string fileDir = string.Format("/Uploads/{0}/", DateTime.Now.ToString("yyyyMM"));
                    if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(fileDir)))
                    {
                        System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(fileDir));
                    }
                    string ext      = System.IO.Path.GetExtension(fudVoice.FileName);
                    string fileName = string.Format("{0}{1}", Guid.NewGuid().ToString("N"), ext);
                    string filePath = fileDir + fileName;
                    fudVoice.SaveAs(HttpContext.Current.Server.MapPath(filePath));
                    Media media = new Media()
                    {
                        MediaName = fudVoice.FileName,
                        MediaFile = filePath,
                        MediaType = MediaUploadType.Voice.ToString().ToLower()
                    };
                    //选中自动同步时,将语音文件自动同步至微信服务器
                    if (cboIsSyn.Checked)
                    {
                        WXConfigDAL           cdal     = new WXConfigDAL();
                        Model.WeiXin.WXConfig wxConfig = cdal.GetWXConfigBySiteCode(Session["strSiteCode"].ToString());
                        if (wxConfig != null)
                        {
                            WeiXinCore.Models.WeiXinConfig weixinConfig = new WeiXinCore.Models.WeiXinConfig()
                            {
                                ID        = wxConfig.WXID,
                                Name      = wxConfig.WXName,
                                Token     = wxConfig.WXToken,
                                AppId     = wxConfig.WXAppID,
                                AppSecret = wxConfig.WXAppSecret
                            };
                            WeiXinCore.WeiXin weixin = new WeiXinCore.WeiXin(weixinConfig);
                            MediaUploadResult obj    = weixin.PostMedia(HttpContext.Current.Server.MapPath(filePath), MediaUploadType.Voice);
                            media.MediaID     = obj.MediaID;
                            media.LastSynTime = DateTime.Now;
                        }
                    }

                    MediaDAL.CreateInstance().InsertInfo(media);


                    //插入自动回复匹配表
                    WXConfigDAL    configdal  = new WXConfigDAL();
                    DataSet        wxconfigds = configdal.GetWXConfigDataList(Session["strSiteCode"].ToString());
                    MsgAutoRule    model      = new MsgAutoRule();
                    MsgAutoRuleDAL dal        = new MsgAutoRuleDAL();
                    model.MatchPattern = keyword.Text;
                    model.Order        = Convert.ToInt32(sort.Text);
                    model.MsgValue     = media.ID;//对应微信媒体文件ID,因微信上传文件有效期为两天,所以需要调度程序定期自动上传
                    model.ID           = Guid.NewGuid().ToString("N").ToUpper();
                    model.Enabled      = 1;
                    model.LastModTime  = DateTime.Now;
                    model.MatchType    = "keywords";
                    model.MsgType      = "voice";
                    if (wxconfigds != null && wxconfigds.Tables.Count > 0 && wxconfigds.Tables[0].Rows.Count > 0)
                    {
                        model.WXConfigID = wxconfigds.Tables[0].Rows[0]["ID"].ToString();
                    }
                    if (dal.AddMsgAutoRule(model))
                    {
                        MessageBox.Show(this, "操作成功!");
                    }
                    else
                    {
                        MessageBox.Show(this, "操作失败!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message);
                }
            }
            else
            {
                MessageBox.Show(this, "请核对信息后再操作!");
            }
        }