コード例 #1
0
        public static void SendMessageToZalo(ZaloClient client, string FilePathZalo, string Is_SendZalo)
        {
            string strMsgLog = string.Empty;

            try
            {
                object objImage;
                string strMsg = string.Empty;
                string AttachmentId = string.Empty;
                string ZaloLink, FileName;
                string FileImg;
                //string strMa_Cbnv, strTen_Cbnv, strEmail, strMa_Kv, strMa_Loai2, strSubject;

                DataTable dtMsg = SQLExec.ExecuteReturnDt("Z_GetMessage_ToZalo");

                if (dtMsg == null || dtMsg.Rows.Count == 0)
                {
                    return;
                }

                foreach (DataRow drmsg in dtMsg.Rows)
                {
                    int MsgID = Convert.ToInt32(drmsg["Ident00"]);
                    ZaloLink = drmsg["ZaloLink"].ToString();
                    objImage = drmsg["File_Content"];
                    FileImg  = FilePathZalo + @"\" + (drmsg["File_Tag"].ToString() == string.Empty ? String.Empty : drmsg["File_ID"].ToString() + "." + drmsg["File_Tag"].ToString());

                    //Common.WriteToFileZaloLog("Start Send Message ToZalo : " + FileImg);
                    if (SaveZaloResource.LoadResourceImage(FileImg, objImage))
                    {
                        ZaloFile Zfile = new ZaloFile(FileImg);
                        Zfile.setMediaTypeHeader("Image/PNG");
                        JObject updatefile = client.uploadImageForOfficialAccountAPI(Zfile);
                        dynamic dynObjFile = JsonConvert.DeserializeObject(updatefile.ToString());
                        AttachmentId = dynObjFile.data.attachment_id;
                    }

                    //Get list employee in branch
                    //string strSQLEm = "Z_GetEmployee_ByTag " + drmsg["Ident00"] + "";


                    if (Is_SendZalo == "Y")
                    {
                        DataTable dtEmployee_Br = SQLExec.ExecuteReturnDt("Z_GetEmployee_ByTag " + MsgID.ToString());
                        if (dtEmployee_Br == null || dtEmployee_Br.Rows.Count == 0)
                        {
                            continue;
                        }

                        foreach (DataRow drR in dtEmployee_Br.Rows)
                        {
                            JObject jSendbr = client.sendImageMessageToUserIdByAttachmentId(drR["Zalo_ID"].ToString(), ZaloLink, AttachmentId);
                        }
                    }
                    else
                    {
                        JObject jSend_hungnv = client.sendImageMessageToUserIdByAttachmentId("5643947530772678208", ZaloLink, AttachmentId);
                    }

                    SQLExec.Execute("Z_UpdateMessageZaloAfterSend " + MsgID.ToString());
                }
            }
            catch (Exception ex)
            {
                //Common.WriteToFileZaloLog("Send Message to Zalo : " + strMsgLog + "-------------\n" + ex.ToString());
            }
        }
コード例 #2
0
        public override void EpointRelease()
        {
            if (ReleaseType == "S")
            {
                string strMsgLog = string.Empty;
                try
                {
                    if (!Directory.Exists(FilePathZalo))
                    {
                        Directory.CreateDirectory(FilePathZalo);
                    }
                    object objImage;
                    string strMsg = string.Empty;
                    string AttachmentId = string.Empty;
                    string ZaloLink, File_Name, Description;
                    string FileImg;
                    //string FilePathZalo
                    //string strMa_Cbnv, strTen_Cbnv, strEmail, strMa_Kv, strMa_Loai2, strSubject;
                    EpointProcessBox.AddMessage("Lấy dữ liệu tin nhắn");

                    DataTable dtMsg = SQLExec.ExecuteReturnDt(" EXEC TUANVIET_OFFICIAL.dbo.Z_GetMessage_ToZalo " + MsgIDCur.ToString());

                    if (dtMsg == null || dtMsg.Rows.Count == 0)
                    {
                        EpointProcessBox.AddMessage("không lấy được dữ liệu tin nhắn");
                        return;
                    }
                    EpointProcessBox.AddMessage("Bắt đầu gửi tin nhắn");
                    //foreach (DataRow drmsg in dtMsg.Rows)
                    //{

                    DataRow drmsg = dtMsg.Rows[0];
                    //int MsgID = Convert.ToInt32(drmsg["Ident00"]);
                    ZaloLink    = drmsg["ZaloLink"].ToString();
                    objImage    = drmsg["File_Content"];
                    File_Name   = drmsg["File_Name"].ToString();
                    Description = drmsg["Description"].ToString();

                    FileImg = FilePathZalo + @"\" + (drmsg["File_Tag"].ToString() == string.Empty ? String.Empty : drmsg["File_ID"].ToString() + "." + drmsg["File_Tag"].ToString());

                    //Common.WriteToFileZaloLog("Start Send Message ToZalo : " + FileImg);
                    if (SaveZaloResource.LoadResourceImage(FileImg, objImage))
                    {
                        ZaloFile Zfile = new ZaloFile(FileImg);
                        Zfile.setMediaTypeHeader("Image/PNG");
                        JObject updatefile = client.uploadImageForOfficialAccountAPI(Zfile);
                        dynamic dynObjFile = JsonConvert.DeserializeObject(updatefile.ToString());
                        AttachmentId = dynObjFile.data.attachment_id;
                    }

                    //Get list employee in branch
                    //string strSQLEm = "Z_GetEmployee_ByTag " + drmsg["Ident00"] + "";

                    strMsg = File_Name + "\n" + Description + "\n" + ZaloLink;
                    if (true)
                    {
                        DataTable dtEmployee_Br = SQLExec.ExecuteReturnDt("EXEC Z_GetEmployee_ByTag " + MsgIDCur.ToString());
                        if (dtEmployee_Br == null || dtEmployee_Br.Rows.Count == 0)
                        {
                            return;
                        }

                        foreach (DataRow drR in dtEmployee_Br.Rows)
                        {
                            JObject jSendbr = client.sendImageMessageToUserIdByAttachmentId(drR["Zalo_ID"].ToString(), strMsg, AttachmentId);
                        }
                    }
                    else
                    {
                        JObject jSend_hungnv = client.sendImageMessageToUserIdByAttachmentId("5643947530772678208", strMsg, AttachmentId);
                    }
                    SQLExec.Execute("EXEC TUANVIET_OFFICIAL.dbo.Z_UpdateMessageZaloAfterSend " + MsgIDCur.ToString());
                    EpointProcessBox.AddMessage("Kết thúc");
                }
                catch (Exception ex)
                {
                    EpointProcessBox.AddMessage("Fail Send Message to Zalo : " + strMsgLog + "-------------\n" + ex.ToString());
                }
            }
            else if (ReleaseType == "G")
            {
                EpointProcessBox.AddMessage("Đang cập nhật thông tin người theo dõi!...................");
                UpdateFollower();
                ReleaseType = string.Empty;
                EpointProcessBox.AddMessage("....................Kết thúc...................");
            }
        }