private bool sendmessage(string openid, string userid)
        {
            DataSet dtWeiXinMsg = TmoShare.getDataSetFromXML(tmo_wechat_consulting);
            //dtWeiXinMsg.Tables[0].Clear();
            DataRow newRow = dtWeiXinMsg.Tables[0].NewRow();

            newRow["we_id"]         = openid;
            newRow["con_content"]   = "医生主动咨询";
            newRow["reply_content"] = ask_content.Text;
            newRow["input_time"]    = System.DateTime.Now;
            newRow["update_time"]   = System.DateTime.Now;

            newRow["user_id"] = userid;
            newRow["doc_id"]  = TmoComm.login_docInfo.doc_id.ToString();
            newRow["con_id"]  = Guid.NewGuid().ToString("N");
            dtWeiXinMsg.Tables[0].Rows.InsertAt(newRow, 0);
            dtWeiXinMsg.AcceptChanges();
            bool answer = (bool)(TmoServiceClient.InvokeServerMethodT <bool>(funCode.AddAsk, new object[] { TmoCommon.TmoShare.getXMLFromDataSet(dtWeiXinMsg) }));

            if (answer)
            {
                string  data = @"<data>
                                <first>
                                    <value></value>
                                    <color></color>
                                </first>
                                <keyword1>
                                    <value></value>
                                    <color></color>
                                </keyword1>
                                <keyword2>
                                    <value></value>
                                    <color></color>
                                </keyword2>
                                <remark>
                                    <value></value>
                                    <color></color>
                                </remark>        
                            </data>";
                DataSet ds   = TmoShare.getDataSetFromXML(data);

                ds.Tables["first"].Rows[0]["value"]    = "尊敬的用户,医生对您进行了提问:";
                ds.Tables["first"].Rows[0]["color"]    = TmoShare.RGBToWebColor(Color.Gray);
                ds.Tables["keyword1"].Rows[0]["value"] = "无";
                ds.Tables["keyword1"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);
                ds.Tables["keyword2"].Rows[0]["value"] = ask_content.Text;
                ds.Tables["keyword2"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);
                ds.Tables["remark"].Rows[0]["value"]   = "感谢您的使用!";
                ds.Tables["remark"].Rows[0]["color"]   = TmoShare.RGBToWebColor(Color.Gray);
                string content    = TmoCommon.TmoShare.GetXml_NO_TITLE(ds);
                string templateID = ConfigHelper.GetConfigString("WX_TEMPLATE_RSID");//模板
                string err_tip    = WeChatHelper.WXTemplateMsgSend(new object[] { "admin", openid, templateID, "", TmoShare.RGBToWebColor(Color.Green), content });

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        void okbtn_Click(object sender, EventArgs e)
        {
            bool answer = TmoServiceClient.InvokeServerMethodT <bool>(funCode.AddReply, new object[] { advise_id.Text, answer_content.Text, doc_code.Text });

            if (answer)
            {
                string openid = weid.Text;

                string  data = @"<data>
                                <first>
                                    <value></value>
                                    <color></color>
                                </first>
                                <keyword1>
                                    <value></value>
                                    <color></color>
                                </keyword1>
                                <keyword2>
                                    <value></value>
                                    <color></color>
                                </keyword2>
                                <remark>
                                    <value></value>
                                    <color></color>
                                </remark>        
                            </data>";
                DataSet ds   = TmoShare.getDataSetFromXML(data);

                ds.Tables["first"].Rows[0]["value"]    = "尊敬的用户,您提出的问题有了新的回复:";
                ds.Tables["first"].Rows[0]["color"]    = TmoShare.RGBToWebColor(Color.Gray);
                ds.Tables["keyword1"].Rows[0]["value"] = advise_content.Text;
                ds.Tables["keyword1"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);
                ds.Tables["keyword2"].Rows[0]["value"] = answer_content.Text;
                ds.Tables["keyword2"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);
                ds.Tables["remark"].Rows[0]["value"]   = "感谢您的使用!";
                ds.Tables["remark"].Rows[0]["color"]   = TmoShare.RGBToWebColor(Color.Gray);
                string content    = TmoCommon.TmoShare.GetXml_NO_TITLE(ds);
                string templateID = ConfigHelper.GetConfigString("WX_TEMPLATE_RSID");
                string err_tip    = WeChatHelper.WXTemplateMsgSend(new object[] { "admin", openid, templateID, "", TmoShare.RGBToWebColor(Color.Green), content });

                this.DialogResult = DialogResult.OK;
                DXMessageBox.Show("回复成功!", true);
            }
            else
            {
                DXMessageBox.Show("回复失败!", true);
            }
        }
Ejemplo n.º 3
0
        private void btnSendTemplateMsg_Click(object sender, EventArgs e)
        {
            string  data = @"<data>
                                <first>
                                    <value></value>
                                    <color></color>
                                </first>
                                <keyword1>
                                    <value></value>
                                    <color></color>
                                </keyword1>
                                <keyword2>
                                    <value></value>
                                    <color></color>
                                </keyword2>
                                <remark>
                                    <value></value>
                                    <color></color>
                                </remark>        
                            </data>";
            DataSet ds   = TmoShare.getDataSetFromXML(data);

            ds.Tables["first"].Rows[0]["value"]    = "尊敬的用户,您刚刚进行测量的结果如下:";
            ds.Tables["first"].Rows[0]["color"]    = TmoShare.RGBToWebColor(Color.Gray);
            ds.Tables["keyword1"].Rows[0]["value"] = "【心率】70次/分钟\n     【血压】113/71mmHg";
            ds.Tables["keyword1"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Navy);
            ds.Tables["keyword2"].Rows[0]["value"] = "2014年12月25日 18时37分";
            ds.Tables["keyword2"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);;
            ds.Tables["remark"].Rows[0]["value"]   = "感谢您的使用!";
            ds.Tables["remark"].Rows[0]["color"]   = TmoShare.RGBToWebColor(Color.Gray);;
            string resCode = WeChatHelper.WXTemplateMsgSend(new object[] { "admin", txt_openid.Text.Trim(), lblTemplate_id.Text, "", TmoShare.ARGBToWebColor(Color.Green), TmoCommon.TmoShare.GetXml_NO_TITLE(ds) });

            if (string.IsNullOrEmpty(resCode) || resCode.Contains("err"))
            {
                MessageBox.Show("模板消息发送失败!\r\n错误原因:" + resCode, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("模板消息发送成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 微信
 /// </summary>
 public static bool SendWeChat(object[] infoValue, out string err_tip)
 {
     lock (wechatLock)
     {
         string openid     = infoValue[1].ToString();
         string data       = infoValue[3].ToString();
         string templateID = ConfigHelper.GetConfigString("WX_TEMPLATE_ID");
         err_tip = WeChatHelper.WXTemplateMsgSend(new object[] { "admin", openid, templateID, "", TmoShare.RGBToWebColor(Color.Green), data });
         return(err_tip.Contains("success"));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 监测数据推送微信
        /// </summary>
        /// <param name="state"></param>
        private void MonitorSendWe(object state)
        {
            string data     = @"<data>
                                <first>
                                    <value></value>
                                    <color></color>
                                </first>
                                <keyword1>
                                    <value></value>
                                    <color></color>
                                </keyword1>
                                <keyword2>
                                    <value></value>
                                    <color></color>
                                </keyword2>
                                <keyword3>
                                    <value></value>
                                    <color></color>
                                </keyword3>
                                <remark>
                                    <value></value>
                                    <color></color>
                                </remark>        
                            </data>";
            string result   = "";
            string testName = "";

            if ((DateTime.Now - lastMonitorSendWeTime).TotalSeconds >= 30) //30秒查询一次
            {
                var dtUser = Tmo_FakeEntityManager.Instance.GetData("tmo_monitor",
                                                                    new[] { "user_id", "mt_code", "mt_valueint", "mt_time", "mt_valuefloat", "mt_isnormal", "id", "mt_timestamp" },
                                                                    "mt_code in (100,101,102,103) and we_send ='2' and mt_time>=date_add(NOW(), interval -7 day)", null, null, null, false, 1000);
                if (TmoShare.DataTableIsNotEmpty(dtUser))
                {
                    List <string> skipIds = new List <string>();
                    foreach (DataRow dr in dtUser.Rows)
                    {
                        string id = dr.GetDataRowStringValue("id");
                        if (skipIds.Contains(id))
                        {
                            continue;                       //跳过处理过的血压数据
                        }
                        string userid = dr.GetDataRowStringValue("user_id");
                        if (string.IsNullOrWhiteSpace(userid))
                        {
                            continue;
                        }
                        //查询微信绑定
                        string myweixin = tmo_userinfo_tokenManager.Instance.GetBindId(userid);
                        //查询亲友是否绑定微信
                        DataSet familyds = tmo_userinfoManager.Instance.IsBindFamily(userid);
                        if (string.IsNullOrWhiteSpace(myweixin) && TmoShare.DataSetIsEmpty(familyds))
                        {
                            continue; //没有绑定微信 跳过
                        }
                        List <string> ids = new List <string>();
                        ids.Add(id);

                        string timestamp = dr.GetDataRowStringValue("mt_timestamp");

                        #region 组织发送内容

                        switch (dr["mt_code"].ToString())
                        {
                        case "100":     //舒张压
                            DataRow[] rows = dtUser.Select(string.Format("mt_code=101 and user_id='{0}' and mt_timestamp='{1}'", userid, timestamp));
                            string    ssy  = null;
                            if (rows.Length > 0)
                            {
                                ssy = rows[0].GetDataRowStringValue("mt_valueint");
                                string ssyid = rows[0].GetDataRowStringValue("id");
                                skipIds.Add(ssyid);
                                ids.Add(ssyid);
                            }

                            if (ssy == null)
                            {
                                result = "【舒张压】" + dr["mt_valueint"].ToString() + "mmHg";
                            }
                            else
                            {
                                result = ssy + "/" + dr.GetDataRowStringValue("mt_valueint") + " mmHg";
                            }
                            testName = "血压";
                            break;

                        case "101":     //收缩压
                            DataRow[] row1s = dtUser.Select(string.Format("mt_code=100 and user_id='{0}' and mt_timestamp='{1}'", userid, timestamp));
                            string    szy   = null;
                            if (row1s.Length > 0)
                            {
                                szy = row1s[0].GetDataRowStringValue("mt_valueint");
                                string szyid = row1s[0].GetDataRowStringValue("id");
                                skipIds.Add(szyid);
                                ids.Add(szyid);
                            }

                            if (szy == null)
                            {
                                result = "【收缩压】" + dr["mt_valueint"].ToString() + "mmHg";
                            }
                            else
                            {
                                result = dr.GetDataRowStringValue("mt_valueint") + "/" + szy + " mmHg";
                            }
                            testName = "血压";
                            break;

                        case "102":     //心率
                            result   = dr["mt_valueint"].ToString() + "次/分钟";
                            testName = "心率";
                            break;

                        case "103":     //血糖
                            result   = dr["mt_valuefloat"].ToString() + "mmol/L";
                            testName = "血糖";
                            break;

                        default:
                            break;
                        }

                        #endregion

                        #region 发送给自己

                        //查询自己是否绑定微信
                        if (!string.IsNullOrEmpty(myweixin))
                        {
                            DataSet ds = TmoShare.getDataSetFromXML(data);

                            ds.Tables["first"].Rows[0]["value"] = "尊敬的用户,您刚刚完成的测量:";
                            ds.Tables["first"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);

                            ds.Tables["keyword1"].Rows[0]["value"] = string.Format("[{0}]", testName);
                            ds.Tables["keyword1"].Rows[0]["color"] = "#507ED3";
                            ds.Tables["keyword2"].Rows[0]["value"] = dr.GetDataRowDateTimeValue("mt_time").ToString("yyyy年MM月dd日 HH:mm:ss");
                            ds.Tables["keyword2"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);
                            ds.Tables["keyword3"].Rows[0]["value"] = result;
                            ds.Tables["keyword3"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Green);
                            ds.Tables["remark"].Rows[0]["value"]   = "建议您养成定期测量" + testName + "的习惯,感谢您的使用!";
                            ds.Tables["remark"].Rows[0]["color"]   = TmoShare.RGBToWebColor(Color.Gray);
                            string content = TmoCommon.TmoShare.GetXml_NO_TITLE(ds);

                            string idstr = string.Join(",", ids);
                            Dictionary <string, object> dicVals = new Dictionary <string, object>();
                            dicVals.Add("push_id", idstr);
                            dicVals.Add("user_code", userid);
                            dicVals.Add("push_type", 6);
                            dicVals.Add("push_address", myweixin);
                            dicVals.Add("content_type", "1");
                            dicVals.Add("content_title", "健康监测消息推送");
                            dicVals.Add("content_value", content);
                            dicVals.Add("push_status", 1);
                            dicVals.Add("doc_code", "admin");
                            dicVals.Add("remark", "weMonitor");

                            bool suc = tmo_push_listManager.Instance.AddToPushList(dicVals);
                            if (suc)
                            {
                                tmo_monitorManager.Instance.UpdateWXState(idstr, 3); //推送中
                            }
                        }

                        #endregion

                        #region 发送给绑定的家人

                        if (TmoShare.DataSetIsNotEmpty(familyds))
                        {
                            #region 用户信息

                            string   username = userid;
                            Userinfo user     = tmo_userinfoManager.Instance.GetUserInfoByID(userid);
                            if (user != null)
                            {
                                username = user.name;
                            }

                            #endregion

                            for (int i = 0; i < familyds.Tables[0].Columns.Count; i++)
                            {
                                DataColumn cloum    = familyds.Tables[0].Columns[i];
                                string     key      = cloum.ColumnName;
                                string     familyId = familyds.Tables[0].Rows[0][key].ToString();
                                if (string.IsNullOrEmpty(familyId))
                                {
                                    continue;
                                }

                                string familyweixin = tmo_userinfo_tokenManager.Instance.GetBindId(familyId);
                                if (!string.IsNullOrWhiteSpace(familyweixin))
                                {
                                    DataSet ds = TmoShare.getDataSetFromXML(data);

                                    ds.Tables["first"].Rows[0]["value"]    = "尊敬的用户,您的亲人" + username + "刚刚完成的测量:";
                                    ds.Tables["first"].Rows[0]["color"]    = TmoShare.RGBToWebColor(Color.Gray);
                                    ds.Tables["keyword1"].Rows[0]["value"] = string.Format("[{0}]", testName);
                                    ds.Tables["keyword1"].Rows[0]["color"] = "#507ED3";
                                    ds.Tables["keyword2"].Rows[0]["value"] = dr.GetDataRowDateTimeValue("mt_time").ToString("yyyy年MM月dd日 HH:mm:ss");
                                    ds.Tables["keyword2"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Gray);
                                    ds.Tables["keyword3"].Rows[0]["value"] = result;
                                    ds.Tables["keyword3"].Rows[0]["color"] = TmoShare.RGBToWebColor(Color.Green);
                                    ds.Tables["remark"].Rows[0]["value"]   = "感谢您的使用!";
                                    ds.Tables["remark"].Rows[0]["color"]   = TmoShare.RGBToWebColor(Color.Gray);
                                    string content = TmoCommon.TmoShare.GetXml_NO_TITLE(ds);

                                    string idstr = string.Join(",", ids);
                                    Dictionary <string, object> dicVals = new Dictionary <string, object>();
                                    dicVals.Add("push_id", idstr + "," + -1 * (i + 1));
                                    dicVals.Add("user_code", userid);
                                    dicVals.Add("push_type", 6);
                                    dicVals.Add("push_address", familyweixin);
                                    dicVals.Add("content_type", "1");
                                    dicVals.Add("content_title", "健康监测消息推送");
                                    dicVals.Add("content_value", content);
                                    dicVals.Add("push_status", 1);
                                    dicVals.Add("doc_code", "admin");
                                    dicVals.Add("remark", "weMonitor");

                                    bool suc = tmo_push_listManager.Instance.AddToPushList(dicVals);
                                    if (suc)
                                    {
                                        tmo_monitorManager.Instance.UpdateWXState(idstr, 3); //推送中
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                }

                lastMonitorSendWeTime = DateTime.Now;
            }

            ((ManualResetEvent)((object[])state)[0]).Set();
        }