Example #1
0
File: WinXin.cs Project: uwitec/O2O
        /// <summary>
        /// 处理图片消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool ProcessImageMessage(ImageReceiveMessage msg, params object[] args)
        {
            try
            {
                // string token = args[0].ToString();
                string token = "";
                IMpClient mpClient = new MpClient();
                AccessTokenGetRequest request = new AccessTokenGetRequest()
                {
                    AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
                };
                AccessTokenGetResponse response = mpClient.Execute(request);
                if (response.IsError)
                {
                    //这里回应1条文本消息,当然您也可以回应其他消息
                    MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "您发送了语音消息");
                    return true;
                }
                else
                {
                    token = response.AccessToken.AccessToken;
                    //这里回复一个图片,当然您也可以回复其他类型的消息
                    return MessageHandler.SendImageReplyMessage(token, msg.ToUserName, msg.FromUserName, AppDomain.CurrentDomain.BaseDirectory + "11.jpg");
                }
            }
            catch (Exception ex)
            {
                //这里回应1条文本消息,当然您也可以回应其他消息
                MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "出错了:" + ex.ToString());
                return true;

            }
        }
Example #2
0
        /// <summary>
        /// 处理语音消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool ProcessVoiceMessage(VoiceReceiveMessage msg, params object[] args)
        {
            string                token    = "";
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                //这里回应1条文本消息,当然您也可以回应其他消息
                MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "您发送了语音消息");
                return(true);
            }
            else
            {
                token = response.AccessToken.AccessToken;
                //这里回复1条语音消息,当然您也可以回复其他类型的信息
                return(MessageHandler.SendVoiceReplyMessage(token, msg.ToUserName, msg.FromUserName, AppDomain.CurrentDomain.BaseDirectory + "11.mp3"));
            }
        }
Example #3
0
        public static string NumberOfCreativesMethod()
        {
            IMpClient mpClient = new MpClient();
            var       request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppId = AppId, AppSecret = AppSecret
                }
            };
            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(null);
            }

            var requestUpload = new GetNumberOfCreativesResquest
            {
                AccessToken = response.AccessToken.AccessToken,
            };
            var createResponse = mpClient.Execute(requestUpload);

            if (createResponse.IsError)
            {
                LogHelper.WriteLog(typeof(StatisticsOperation), createResponse.ErrInfo.ErrMsg);
                return(createResponse.ErrInfo.ErrMsg);
            }
            var jsonSerializer = new JavaScriptSerializer();

            return(jsonSerializer.Serialize(createResponse.Body));
        }
Example #4
0
        public static string NewCreativeTemporaryMethod()
        {
            string    imgPath  = "D:/Image/WeChatImage.jpg";
            IMpClient mpClient = new MpClient();
            var       request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppId = AppId, AppSecret = AppSecret
                }
            };
            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(null);
            }

            var requestUpload = new UploadMediaRequest()
            {
                AccessToken = response.AccessToken.AccessToken,
                Type        = "image",
                FileName    = imgPath
            };
            var createResponse = mpClient.Execute(requestUpload);

            if (createResponse.IsError)
            {
                LogHelper.WriteLog(typeof(StatisticsOperation), createResponse.ErrInfo.ErrMsg);
                return(createResponse.ErrInfo.ErrMsg);
            }
            var jsonSerializer = new JavaScriptSerializer();

            return(jsonSerializer.Serialize(createResponse.Body));
        }
Example #5
0
        /// <summary>
        /// 发送视频客服信息
        /// </summary>
        public static void SendVideoCustomMessageTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }
            var response2 = MessageHandler.SendVideoCustomMessage(response.AccessToken.AccessToken, "oSFK4twKCGHhYZazqFMIcAx4GshQ", "美好的视屏", "视频描述", "d:\\2771cae7-8756-4dd4-8491-976589ab17cc.mp4");

            response2 = MessageHandler.SendVideoCustomMessage(response.AccessToken.AccessToken, "oSFK4twW7yL_vR0ya3jYpT-H19lY", "视频客服信息", "视频客服信息描述", "d:\\2771cae7-8756-4dd4-8491-976589ab17cc.mp4");



            if (response2.IsError)
            {
                Console.WriteLine("发送失败");
            }
            else
            {
                Console.WriteLine("发送成功");
            }
        }
Example #6
0
        public Client()
        {
            // get data from connection.cfg
            XDocument doc = XDocument.Load("connection.config");

            var _ip = doc.Descendants("ip");

            ip = "";
            foreach (var i in _ip)
            {
                ip = i.Value;
            }

            var _port = doc.Descendants("port");

            port = 0;
            foreach (var i in _port)
            {
                port = int.Parse(i.Value);
            }

            OnlineFriendsList   = null;
            OfflineFriendsList  = null;
            OnlineUsersList     = null;
            OfflineUsersList    = null;
            IncomeRequestsList  = null;
            OutcomeRequestsList = null;

            Name          = null;
            client        = new MpClient();
            Conversations = new Conversations();

            ConnectionBreaks += delegate { isLoggedIn = false; };
        }
Example #7
0
        public WeiXin.Domain.User GetUserInfo(string OpenID)
        {
            GetUserInfoResponse response = null;

            int retry = 0;

            do
            {
                IMpClient mpClient = new MpClient();

                GetUserInfoRequest request = new GetUserInfoRequest()
                {
                    AccessToken = this.GetAccessToken(),
                    OpenId      = OpenID,
                };

                response = mpClient.Execute(request);
                if (!RefreshAccessToken(response, request.AccessToken))
                {
                    break;
                }
                retry++;
            } while (retry < 2 && response.IsError);
            if (response.IsError)
            {
                LogHelper.WriteInfo("faild", "获取OpenID:" + OpenID + "基本信息失败。获取用户基本信息失败,错误信息为:" + response.ErrInfo.ErrCode + "-" + response.ErrInfo.ErrMsg);
                return(null);
            }
            else
            {
                LogHelper.WriteInfo("sucess", "获取OpenID:" + OpenID + "基本信息成功");
                return(response.UserInfo);
            }
        }
Example #8
0
        /// <summary>
        /// 发送文本客服信息测试
        /// </summary>
        public static void SendTextCustomMessageTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }
            var response2 = MessageHandler.SendTextCustomMessage(response.AccessToken.AccessToken, "oSFK4twKCGHhYZazqFMIcAx4GshQ", "文本客服消息" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            if (response2.IsError)
            {
                Console.WriteLine("发送失败");
            }
            else
            {
                Console.WriteLine("发送成功");
            }
        }
Example #9
0
        /// <summary>
        /// 发送语音客服信息测试
        /// </summary>
        public static void SendVoiceCustomMessageTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }
            var response2 = MessageHandler.SendVoiceCustomMessage(response.AccessToken.AccessToken, "oSFK4twKCGHhYZazqFMIcAx4GshQ", "d:\\11.mp3");

            if (response2.IsError)
            {
                Console.WriteLine("发送失败");
            }
            else
            {
                Console.WriteLine("发送成功");
            }
        }
Example #10
0
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        public static string GetUserInfo(string openId)
        {
            try
            {
                IMpClient mpClient = new MpClient();
                var       request  = new AccessTokenGetRequest()
                {
                    AppIdInfo = new AppIdInfo()
                    {
                        AppId = AppId, AppSecret = AppSecret
                    }
                };
                var response = mpClient.Execute(request);
                if (response.IsError)
                {
                    return(null);
                }

                var request2 = new GetUserInfoRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    OpenId      = openId
                };

                var response2 = mpClient.Execute(request2);

                return(Tools.ToJsonString(response2.UserInfo));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(UserGroupOperation), ex.Message);
                throw new Exception(ex.Message);
            }
        }
Example #11
0
        /// <summary>
        /// 获取用户分组ID
        /// </summary>
        public static GetUserGroupResponse GetUserGroupId(string userId)
        {
            try
            {
                IMpClient mpClient = new MpClient();
                var       request  = new AccessTokenGetRequest()
                {
                    AppIdInfo = new AppIdInfo()
                    {
                        AppId = AppId, AppSecret = AppSecret
                    }
                };
                var response = mpClient.Execute(request);
                if (response.IsError)
                {
                    return(null);
                }

                var request2 = new GetUserGroupRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    UserId      = userId
                };

                return(mpClient.Execute(request2));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(UserGroupOperation), ex);
                throw new Exception(ex.Message);
            }
        }
Example #12
0
 /// <summary>
 /// 处理图片消息
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public bool ProcessImageMessage(ImageReceiveMessage msg, params object[] args)
 {
     try
     {
         // string token = args[0].ToString();
         string                token    = "";
         IMpClient             mpClient = new MpClient();
         AccessTokenGetRequest request  = new AccessTokenGetRequest()
         {
             AppIdInfo = new AppIdInfo()
             {
                 AppID = appId, AppSecret = appSecret
             }
         };
         AccessTokenGetResponse response = mpClient.Execute(request);
         if (response.IsError)
         {
             //这里回应1条文本消息,当然您也可以回应其他消息
             MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "您发送了语音消息");
             return(true);
         }
         else
         {
             token = response.AccessToken.AccessToken;
             //这里回复一个图片,当然您也可以回复其他类型的消息
             return(MessageHandler.SendImageReplyMessage(token, msg.ToUserName, msg.FromUserName, AppDomain.CurrentDomain.BaseDirectory + "11.jpg"));
         }
     }
     catch (Exception ex)
     {
         //这里回应1条文本消息,当然您也可以回应其他消息
         MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "出错了:" + ex.ToString());
         return(true);
     }
 }
Example #13
0
        private void GetOpenID(HttpContext context)
        {
            string code = context.Request.QueryString["code"];

            IMpClient client  = new MpClient();
            var       request = new WeiXin.Request.Oauth2AccessTokenGetRequest()
            {
                AppIdInfo = new WeiXin.Domain.AppIdInfo()
                {
                    AppID     = MessageProcessor.Instance.mAppId,
                    AppSecret = MessageProcessor.Instance.mAppSecret
                },
                Code = code,
            };
            var response = client.Execute(request);

            if (!response.IsError)
            {
                string openId = response.AccessToken.OpenID;
                LogHelper.WriteDebug(LogModule, "获取OpenID(" + code + ")成功:" + openId);
                WebUtil.WriteJson(context, openId);
                return;
            }
            else
            {
                LogHelper.WriteError(LogModule, "获取OpenID(" + code + ")失败:" + response.ErrInfo.ToString(), null);
            }
            WebUtil.WriteJson(context, null);
        }
Example #14
0
        /// <summary>
        /// 回复数据
        /// </summary>
        void savePave()
        {
            string appId     = System.Configuration.ConfigurationManager.AppSettings["YHQAppId"].Trim();
            string appSecret = System.Configuration.ConfigurationManager.AppSettings["YHQAppSecret"].Trim();
            string openid    = Utils.GetQueryStringValue("openid");
            string getMsg    = Utils.GetFormValue("txtMsg");

            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("位置错误..");
                return;
            }
            var response2 = MessageHandler.SendTextCustomMessage(response.AccessToken.AccessToken, openid, getMsg);

            Response.Clear();
            if (response2.IsError)
            {
                Response.Write(UtilsCommons.AjaxReturnJson("0", "发送失败"));
            }
            else
            {
                Response.Write(UtilsCommons.AjaxReturnJson("1", "发送成功"));
            }
            Response.End();
        }
Example #15
0
        /// <summary>
        /// 发送音乐客服消息测试
        /// </summary>
        public static void SendMusicCustomMessageTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }
            //var response2 = MessageHandler.SendMusicCustomMessage(response.AccessToken.AccessToken, "oSFK4twKCGHhYZazqFMIcAx4GshQ", "音乐标题", "音乐描述","","" "d:\\UP.jpg");

            var response2 = MessageHandler.SendMusicCustomMessage(response.AccessToken.AccessToken, "oSFK4twKCGHhYZazqFMIcAx4GshQ", "音乐标题", "音乐描述", "http://wx.011011.com/baba.mp3", "http://wx.011011.com/baba.mp3", "d:\\UP.jpg");

            response2 = MessageHandler.SendMusicCustomMessage(response.AccessToken.AccessToken, "oSFK4twW7yL_vR0ya3jYpT-H19lY", "音乐标题", "音乐描述", "http://wx.011011.com/baba.mp3", "http://wx.011011.com/baba.mp3", "d:\\UP.jpg");



            if (response2.IsError)
            {
                Console.WriteLine("发送失败");
            }
            else
            {
                Console.WriteLine("发送成功");
            }
        }
Example #16
0
        /// <summary>
        /// 获取用户分组ID测试
        /// </summary>
        public static void GetUserGroupIdTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }

            GetUserGroupRequest request2 = new GetUserGroupRequest()
            {
                AccessToken = response.AccessToken.AccessToken,
                UserId      = "oSFK4t4xIdeddd4wpxXaUmtKKpMA"
            };

            var response2 = mpClient.Execute(request2);

            if (response2.IsError)
            {
                Console.WriteLine("查询用户分组ID失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg);
            }
            else
            {
                Console.WriteLine("查询用户分组ID成功,分组ID为:" + response2.GroupId);
            }
        }
Example #17
0
        public static QrCodeCreateResponse SendQrCodeCreateRequest(int sceneID, string QrType, int ExpireSeconds)
        {
            int retry = 0;
            QrCodeCreateResponse res = null;

            do
            {
                QrCodeCreateRequest reqeust = new QrCodeCreateRequest()
                {
                    AccessToken = GetAccessToken(null),
                    AppIdInfo   = new AppIdInfo()
                    {
                        AppID     = PaymentConfig.WeiXinConfig.AppID,
                        AppSecret = PaymentConfig.WeiXinConfig.AppSecret,
                    },
                    QrCodeCreateMessage = new QrCodeCreateMessage()
                    {
                        SceneId       = sceneID,
                        ExpireSeconds = ExpireSeconds,
                        ActionName    = QrType,
                    }
                };
                IMpClient mp = new MpClient();

                res = mp.Execute(reqeust);
                if (!RefreshAccessToken(res, reqeust.AccessToken))
                {
                    break;
                }
                retry++;
            } while (retry < 2 && res.IsError);
            return(res);
        }
Example #18
0
        /// <summary>
        /// Handle client.
        /// </summary>
        /// <param name="client">Connected client.</param>
        private async Task HandleClient(MpClient client)
        {
            log.Info($"Client connected. ip {((IPEndPoint)client.tcpClient.Client.RemoteEndPoint).Address.ToString()}");

            await Task.Run(() =>
            {
                try
                {
                    // recieve client's message
                    Message message = client.ReceiveMessage();

                    // login / register
                    if (message != null)
                    {
                        if (message is LoginRequestMessage)
                        {
                            LoginClient(client, (LoginRequestMessage)message);
                        }
                        else if (message is RegisterRequestMessage)
                        {
                            RegisterClient(client, (RegisterRequestMessage)message);
                        }
                    }
                }
                catch (ConnectionInterruptedException e)
                {
                    log.Error("Connection with client brokes.", e);
                }
            });
        }
Example #19
0
        /// <summary>
        /// 回复数据
        /// </summary>
        void savePave()
        {
            string appId = System.Configuration.ConfigurationManager.AppSettings["YHQAppId"].Trim();
            string appSecret = System.Configuration.ConfigurationManager.AppSettings["YHQAppSecret"].Trim();
            string openid = Utils.GetQueryStringValue("openid");
            string getMsg = Utils.GetFormValue("txtMsg");

            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                Console.WriteLine("位置错误..");
                return;
            }
            var response2 = MessageHandler.SendTextCustomMessage(response.AccessToken.AccessToken, openid, getMsg);
            Response.Clear();
            if (response2.IsError)
            {
                Response.Write(UtilsCommons.AjaxReturnJson("0", "发送失败"));
            }
            else
            {
                Response.Write(UtilsCommons.AjaxReturnJson("1", "发送成功"));
            }
            Response.End();
        }
Example #20
0
        /// <summary>
        /// 获取微信接口凭证AccessToken
        /// </summary>
        /// <returns></returns>
        public string GetAccessToken(string keyValue = "")
        {
            string                accessToken = string.Empty;
            string                _appId      = WeixinConfig.Instance.AppId;
            string                appSecret   = WeixinConfig.Instance.AppSecret;
            IMpClient             mpClient    = new MpClient();
            AccessTokenGetRequest request     = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = _appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                return("0");
            }
            accessToken = response.AccessToken.AccessToken;
            int timestampNow = ConvertDateTimeInt(DateTime.Now);

            accessTokenBLL.SaveForm(keyValue, new AccessTokenEntity {
                Id         = keyValue,
                ModifyDate = DateTime.Now,
                Timestamp  = timestampNow,
                Token      = accessToken
            });
            return(accessToken);
        }
Example #21
0
        /// <summary>
        /// 取得菜单
        /// </summary>
        /// <returns></returns>
        public static List <Button> GetMenu()
        {
            //取得菜单信息
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(null);
            }
            else
            {
                GetMenuRequest getRequest = new GetMenuRequest()
                {
                    AccessToken = response.AccessToken.AccessToken
                };
                var getResponse = mpClient.Execute(getRequest);
                if (getResponse.IsError)
                {
                    return(null);
                }
                else
                {
                    var m = getResponse.Menu.menu.button;
                    return(m);
                }
            }
        }
Example #22
0
        /// <summary>
        /// 获取关注者列表测试
        /// </summary>
        public static void GetAttentionsTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }

            GetAttentionsRequest request2 = new GetAttentionsRequest()
            {
                AccessToken = response.AccessToken.AccessToken
            };

            var response2 = mpClient.Execute(request2);

            if (response2.IsError)
            {
                Console.WriteLine("获取关注者列表失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg);
            }
            else
            {
                Console.WriteLine("获取关注者列表成功");
                Console.WriteLine(Tools.ToJsonString(response2.Attentions));
            }
        }
Example #23
0
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="OpenId">用户OpenId</param>
        /// <returns></returns>
        public static User GetUserInfo(string OpenId)
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(null);
            }

            GetUserInfoRequest request2 = new GetUserInfoRequest()
            {
                AccessToken = response.AccessToken.AccessToken,
                OpenId      = OpenId,
            };

            var response2 = mpClient.Execute(request2);

            if (response2.IsError)
            {
                return(null);
            }
            else
            {
                return(response2.UserInfo);
            }
        }
Example #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string weixin_appid = "";
            string weixin_secret = "";
            weixin_appid = Utils.GetConfigString("", "YHQAppId").Trim();
            weixin_secret = Utils.GetConfigString("", "YHQAppSecret").Trim();

            if (Utils.GetQueryStringValue("sync") != "1") Utils.RCWE("");

            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = weixin_appid, AppSecret = weixin_secret }
            };

            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                Utils.RCWE("获取令牌环失败..");
            }

            GetAttentionsRequest request2 = new GetAttentionsRequest()
            {
                AccessToken = response.AccessToken.AccessToken
            };

            var response2 = mpClient.Execute(request2);
            if (response2.IsError)
            {
                Utils.RCWE("获取关注者列表失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg);
            }

            foreach (var item in response2.Attentions.data.openid)
            {
                var info1 = Eyousoft_yhq.Web.BsendMsg.WeiXin.GetUserInfo(item);

                var info = new Eyousoft_yhq.Model.MWeiXinYongHuInfo();
                info.city = info1.City;
                info.country = info1.Country;
                info.createtime = DateTime.Now;
                info.headimgurl = info1.HeadImgUrl;
                info.language = info1.Language;
                info.latesttime = DateTime.Now;
                info.nickname = info1.NickName;
                info.openid = info1.OpenId;
                info.province = info1.Province;
                info.sex = info1.Sex;
                info.subscribe = info1.SubScribe;
                info.subscribe_time = info1.SubscribeTime;
                info.unionid = string.Empty;
                info.YongHuId = Guid.NewGuid().ToString();

                new Eyousoft_yhq.BLL.BWeiXin().YongHu_C(info);
            }

            Utils.RCWE("获取关注者列表成功");
        }
        public static string UploadCreativeGraphicMessageMethod()
        {
            IMpClient mpClient = new MpClient();
            var       request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppId = AppId, AppSecret = AppSecret
                }
            };
            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                return(null);
            }
            GraphicInterfaceMessage permanent = new GraphicInterfaceMessage
            {
                ThumbMediaId     = "TpuIFr0VPcAnD3nObZzDiuLFJeEK8repP9HOTg7WwBmgHCTZdWHRj7ZOsO67H8SG",
                Author           = "ceshi",
                Title            = "测试标题",
                ContentSourceUrl = "www.baidu.com",
                Content          = "测试内容",
                Digest           = "测试的描述打发打发",
                ShowCoverPic     = "1"
            };

            List <GraphicInterfaceMessage> list = new List <GraphicInterfaceMessage> {
                permanent
            };

            GraphicInterfaceMessageList meList = new GraphicInterfaceMessageList {
                GraphicInterfaceMessagesList = list
            };

            InterfaceMessageList meMaterial = new InterfaceMessageList
            {
                GraphicInterface = meList
            };

            var s             = meMaterial.ToJsonString();
            var requestUpload = new GraphicInterfaceMessageRequest
            {
                AccessToken = response.AccessToken.AccessToken,
                SendData    = s
            };
            var createResponse = mpClient.Execute(requestUpload);

            if (createResponse.IsError)
            {
                LogHelper.WriteLog(typeof(StatisticsOperation), createResponse.ErrInfo.ErrMsg);
                return(createResponse.ErrInfo.ErrMsg);
            }
            var jsonSerializer = new JavaScriptSerializer();

            return(jsonSerializer.Serialize(createResponse.Body));
        }
Example #26
0
    public MpHandler(MpClient client)
    {
        OtherPlayers = new Dictionary<string, OtherPlayer>();
        DelegatedWork = new List<Action>();

        Client = client;
        Client.OnSomeoneJoined += SomeoneJoined;
        Client.OnSomeoneDropped += SomeoneDropped;;
        Client.OnPositionUpdate += PositionUpdate;
    }
Example #27
0
    public MpHandler(MpClient client)
    {
        OtherPlayers  = new Dictionary <string, OtherPlayer>();
        DelegatedWork = new List <Action>();

        Client = client;
        Client.OnSomeoneJoined  += SomeoneJoined;
        Client.OnSomeoneDropped += SomeoneDropped;;
        Client.OnPositionUpdate += PositionUpdate;
    }
Example #28
0
        /// <summary>
        /// Try to register client. Send response about result.
        /// </summary>
        /// <param name="client">client.</param>
        /// <param name="message">client's message.</param>
        private void RegisterClient(MpClient client, RegisterRequestMessage message)
        {
            Message response;

            if (string.IsNullOrEmpty(message.Login) ||
                string.IsNullOrEmpty(message.Password) ||
                message.Login.Length > 20 ||
                message.Password.Length > 30)
            {
                response = new LoginRegisterResponseMessage {
                    Response = LoginRegisterResponse.Error
                };
            }
            else
            {
                if (DBoperations.Register(message.Login, message.Password))
                {
                    log.Info($"Client registered: {message.Login}");

                    response = new LoginRegisterResponseMessage {
                        Response = LoginRegisterResponse.Success
                    };
                }
                else
                {
                    response = new LoginRegisterResponseMessage {
                        Response = LoginRegisterResponse.Fail
                    };
                }
            }

            try
            {
                // response to client
                client.SendMessage(response);
            }
            catch (ConnectionInterruptedException e)
            {
                log.Error("Connection with client brokes.", e);
            }

            // close connection
            log.Info($"Client disconnected. ip {((IPEndPoint)client.tcpClient.Client.RemoteEndPoint).Address.ToString()}");

            try
            {
                client.Close();
            }
            catch (ConnectionInterruptedException e)
            {
                log.Error(e);
            }
        }
Example #29
0
        public static string GetDailyGraphicMassMethod()
        {
            //DateTime StartDate = DateTime.Parse("2016-08-01");
            //DateTime EndDate = DateTime.Parse("2016-08-04");
            string StartDate = "2016-08-01";
            string EndDate   = "2016-08-01";

            try
            {
                IMpClient mpClient = new MpClient();
                var       request  = new AccessTokenGetRequest()
                {
                    AppIdInfo = new AppIdInfo()
                    {
                        AppId = AppId, AppSecret = AppSecret
                    }
                };
                var response = mpClient.Execute(request);
                if (response.IsError)
                {
                    return(null);
                }

                var startDate = new Statistics
                {
                    BeginDate = StartDate,
                    EndDate   = EndDate
                };

                var createRequest = new GetDailyGraphicMassRequest
                {
                    AccessToken = response.AccessToken.AccessToken,
                    SendData    = startDate.ToCreateJsonString()
                };

                var createResponse = mpClient.Execute(createRequest);
                if (createResponse.IsError)
                {
                    LogHelper.WriteLog(typeof(StatisticsOperation), createResponse.ErrInfo.ErrMsg);
                    return(createResponse.ErrInfo.ErrMsg);
                }
                var jsonSerializer = new JavaScriptSerializer();
                return(jsonSerializer.Serialize(createResponse.DailyGraphicBulkStatistics));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(StatisticsOperation), ex);
                throw new Exception(ex.Message);
            }
        }
Example #30
0
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="openid"></param>
        private UserInfoR GetUserInfo(string openid)
        {
            if (string.IsNullOrEmpty(openid))
            {
                return(null);
            }
            StringBuilder         url      = new StringBuilder();
            IMpClient             mpClient = new MpClient();
            UserInfoR             userinfo = null;
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = ConfigHelper.AppSettings("WEPAY_WEB_APPID"), AppSecret = ConfigHelper.AppSettings("WEPAY_WEb_AppSecret")
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                userinfo            = new FJCWebApp.CommonClass.UserInfoR();
                userinfo.headimgurl = "/Content/Images/top.png";
                userinfo.province   = response.ErrInfo.ErrMsg;
                userinfo.city       = response.ErrInfo.ErrCode.ToString();
            }
            else
            {
                url.AppendFormat("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", response.AccessToken.AccessToken, openid);

                var client  = new HttpClient();
                var retJson = client.GetAsync(url.ToString()).Result.Content.ReadAsStringAsync().Result;

                try
                {
                    Business.Base_SysLogBll.Instance.WriteLog("", Business.OperationType.Query, "-1", retJson);
                    userinfo = JsonConvert.DeserializeObject <UserInfoR>(retJson);
                }
                catch (Exception ex)
                {
                    userinfo            = new FJCWebApp.CommonClass.UserInfoR();
                    userinfo.headimgurl = "/Content/Images/top.png";
                    userinfo.province   = ex.Message;
                    userinfo.city       = response.Body;
                }
            }

            return(userinfo);
        }
Example #31
0
        /// <summary>
        /// 修改分组
        /// </summary>
        public static void ModifyGroup()
        {
            try
            {
                IMpClient mpClient = new MpClient();
                var       request  = new AccessTokenGetRequest()
                {
                    AppIdInfo = new AppIdInfo()
                    {
                        AppId = AppId, AppSecret = AppSecret
                    }
                };
                var response = mpClient.Execute(request);
                if (response.IsError)
                {
                    return;
                }

                var groupInfo = new Group()
                {
                    Id   = "101",
                    Name = "修改后的分组"
                };

                var request2 = new ModifyGroupRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    GroupInfo   = groupInfo,
                    SendData    = groupInfo.ToModifyJsonString()
                };

                var response2 = mpClient.Execute(request2);
                if (response2.IsError)
                {
                    LogHelper.WriteLog(typeof(UserGroupOperation), response2.ErrInfo.ErrMsg);
                }
                else
                {
                    GetGroups(); //查询一把,显示一下信息
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(UserGroupOperation), ex);
                throw new Exception(ex.Message);
            }
        }
        public static void QrCodeCreateMethod()
        {
            IMpClient mpClient = new MpClient();
            var       request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppId = AppId, AppSecret = AppSecret
                }
            };
            var response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }

            var msg = new QrCodeCreateMessage()
            {
                SceneId        = 22,
                ExpireSeconds  = 1800,
                ActionName     = "QR_LIMIT_SCENE", //QR_SCENE为临时,QR_LIMIT_SCENE为永久
                LocalStoredDir = "D:\\"
            };

            var createRequest = new QrCodeCreateRequest()
            {
                AccessToken         = response.AccessToken.AccessToken,
                QrCodeCreateMessage = msg,
                SendData            = msg.ToJsonString()
            };

            var createResponse = mpClient.Execute(createRequest);

            ticketKey = createResponse.QrCodeUrl;
            if (createResponse.IsError)
            {
                HttpContext.Current.Response.Write("创建二维码失败,错误信息为:" + createResponse.ErrInfo.ErrCode + "-" + createResponse.ErrInfo.ErrMsg);
            }
            else
            {
                HttpContext.Current.Response.Write("创建二维码成功,二维码链接地址为:" + createResponse.QrCodeUrl + "本地存储路径为:" + createResponse.LocalFilePath);
            }
        }
Example #33
0
        /// <summary>
        /// 修改分组测试
        /// </summary>
        public static void ModifyGroupTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }

            Group groupInfo = new Group()
            {
                id   = "101",
                name = "修改后的分组"
            };

            ModifyGroupRequest request2 = new ModifyGroupRequest()
            {
                AccessToken = response.AccessToken.AccessToken,
                GroupInfo   = groupInfo,
                SendData    = groupInfo.ToModifyJsonString()
            };

            var response2 = mpClient.Execute(request2);

            if (response2.IsError)
            {
                Console.WriteLine("修改分组失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg);
            }
            else
            {
                Console.WriteLine("修改分组信息成功");
                GetGroupsTest(); //查询一把,显示一下信息
            }
        }
Example #34
0
        public string GetJsApiTicket()
        {
            if (string.IsNullOrEmpty(mJsApiTicket) || mJsApiTicketExpiredTime <= DateTime.Now)
            {
                JsApiTicketGetResponse response = null;

                DateTime timenow = DateTime.MinValue;
                int      retry   = 0;
                do
                {
                    timenow = DateTime.Now;
                    IMpClient             mpClient = new MpClient();
                    JsApiTicketGetRequest request  = new JsApiTicketGetRequest()
                    {
                        AppIdInfo = new AppIdInfo()
                        {
                            AppID = mAppId, AppSecret = mAppSecret
                        },
                        AccessToken = this.GetAccessToken(),
                    };
                    response = mpClient.Execute(request);

                    if (!RefreshAccessToken(response, request.AccessToken))
                    {
                        break;
                    }
                    retry++;
                } while (retry < 2 && response.IsError);

                if (response.IsError)
                {
                    string msg = string.Format("获取JsApiTicket失败。 Code:{0},Msg:{1}", response.ErrInfo.ErrCode, response.ErrInfo.ErrMsg);
                    LogHelper.WriteError(LogModule, msg, null);
                    throw new ApplicationException(msg);
                }
                else
                {
                    mJsApiTicket            = response.Ticket.Ticket;
                    mJsApiTicketExpiredTime = timenow.AddSeconds(response.Ticket.ExpiresIn).AddMinutes(-10);
                }
            }
            return(mJsApiTicket);
        }
Example #35
0
File: WinXin.cs Project: uwitec/O2O
        /// <summary>
        /// 获取关注者列表
        /// </summary>
        /// <param name="AttentionsList">返回关注的列表</param>
        /// <param name="NextOpenId">超过一万时最后一个关注OPENID</param>
        /// <returns></returns>
        public static WeiXinResult GetAttentions(ref List<string> AttentionsList, string NextOpenId)
        {
            WeiXinResult AttentionsResult = new WeiXinResult();
            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                AttentionsResult.IsResult = false;
                AttentionsResult.ResultMsg = "获取令牌环失败";
                return AttentionsResult;

            }
            string AccessToken = response.AccessToken.AccessToken;
            GetAttentionsRequest request2 = new GetAttentionsRequest()
            {
                AccessToken = AccessToken,
                NextOpenId = NextOpenId
            };

            var response2 = mpClient.Execute(request2);
            if (response2.IsError)
            {
                AttentionsResult.IsResult = false;
                AttentionsResult.ResultMsg = "获取关注者列表失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg;
                return AttentionsResult;
            }
            else
            {
                var list = response2.Attentions;
                if (list.total > 0)
                {
                    if (list.data.openid.Count > 0)
                    {
                        AttentionsList.AddRange(list.data.openid);
                        if (list.total > 10000 && !String.IsNullOrEmpty(list.next_openid))//超过一万
                        {
                            return GetAttentions(ref AttentionsList, list.next_openid);
                        }
                        else
                        {
                            // Adpost.Finawin.Utility.ConfigClass.SetConfigKeyValue("next_openid", list.next_openid);
                            AttentionsResult.IsResult = true;
                            AttentionsResult.ResultMsg = "获取关注者列表成功";
                            return AttentionsResult;
                        }
                    }
                    else
                    {
                        AttentionsResult.IsResult = false;
                        AttentionsResult.ResultMsg = "无关注者数据";
                        return AttentionsResult;
                    }
                }
                else
                {
                    AttentionsResult.IsResult = false;
                    AttentionsResult.ResultMsg = "无关注者数据";
                    return AttentionsResult;
                }
            }
        }
Example #36
0
File: WinXin.cs Project: uwitec/O2O
 /// <summary>
 /// 处理语音消息
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public bool ProcessVoiceMessage(VoiceReceiveMessage msg, params object[] args)
 {
     string token = "";
     IMpClient mpClient = new MpClient();
     AccessTokenGetRequest request = new AccessTokenGetRequest()
     {
         AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
     };
     AccessTokenGetResponse response = mpClient.Execute(request);
     if (response.IsError)
     {
         //这里回应1条文本消息,当然您也可以回应其他消息
         MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "您发送了语音消息");
         return true;
     }
     else
     {
         token = response.AccessToken.AccessToken;
         //这里回复1条语音消息,当然您也可以回复其他类型的信息
         return MessageHandler.SendVoiceReplyMessage(token, msg.ToUserName, msg.FromUserName, AppDomain.CurrentDomain.BaseDirectory + "11.mp3");
     }
 }
Example #37
0
File: WinXin.cs Project: uwitec/O2O
        /// <summary>
        /// 创建菜单
        /// </summary>
        public static WeiXinResult CreateMenu()
        {
            WeiXinResult rv = new WeiXinResult { IsResult = false, ResultMsg = "系统错误!" };
            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                rv.ResultMsg = "获取令牌环失败";
                return rv;
            }
            else
            {
                Menu menu = new Menu();
                List<Button> button = new List<Weixin.Mp.Sdk.Domain.Button>();
                #region 菜单一 产品中心
                Button subBtn1 = new Button()
                {
                    key = "guoneiyou",
                    name = "国内游",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=0"
                };
                Button subBtn2 = new Button()
                {
                    key = "guojiyou",
                    name = "国际游",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=1"

                };
                Button subBtn3 = new Button()
                {
                    key = "chanpintuijian",
                    name = "产品推荐",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductList.aspx?tuijian=1"
                };
                Button subBtn4 = new Button()
                {
                    key = "chanpinmachaxun",
                    name = "产品码查询",
                    sub_button = null,
                    type = "click",
                    url = "http://www.4008005216.com/AppPage/weixin/Register.aspx"
                };

                Button subBtn5 = new Button()
                {
                    key = "guoneijipiao",
                    name = "国内机票",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/jp_Search.aspx"
                };
                List<Button> subBtnAll = new List<Button>();
                subBtnAll.Add(subBtn1);
                subBtnAll.Add(subBtn2);
                subBtnAll.Add(subBtn3);
                subBtnAll.Add(subBtn4);
                subBtnAll.Add(subBtn5);
                Button btn = new Button()
                {
                    key = "menu1",
                    name = "旅游超市",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll
                };
                button.Add(btn);

                #endregion
                #region 菜单二 会员中心
                Button Menu2SubBtn1 = new Button()
                {
                    key = "dingdanguanli",
                    name = "订单管理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/OrderList.aspx"
                };
                Button Menu2SubBtn2 = new Button()
                {
                    key = "zhanghuguanli",
                    name = "账户管理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/updateUser.aspx"
                };
                Button Menu2SubBtn3 = new Button()
                {
                    key = "yuyue",
                    name = "预约办理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/YuYue.aspx"
                };

                string _weidianurl = "https://open.weixin.qq.com/connect/oauth2/authorize?";
                _weidianurl += "appid=" + appId;
                _weidianurl += "&redirect_uri=http://www.4008005216.com/WeiXin/oauth2_authorize.aspx";
                _weidianurl += "&response_type=code";
                _weidianurl += "&scope=snsapi_base";
                _weidianurl += "&state=weidian_snsapi_base";
                _weidianurl += "#wechat_redirect";

                Button Menu2SubBtn4 = new Button()
                {
                    key = "wodeweidian",
                    name = "我的微店",
                    sub_button = null,
                    type = "view",
                    url = _weidianurl
                };
                Button Menu2SubBtn5 = new Button()
                {
                    key = "fenxiang",
                    name = "最新分享",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/HuiYuanWeiXin/TuWenFenXiang.aspx"
                };
                List<Button> subBtnAll2 = new List<Button>();
                subBtnAll2.Add(Menu2SubBtn1);
                subBtnAll2.Add(Menu2SubBtn2);
                subBtnAll2.Add(Menu2SubBtn3);
                subBtnAll2.Add(Menu2SubBtn4);
                subBtnAll2.Add(Menu2SubBtn5);

                btn = new Button()
                {
                    key = "huiyuanzhongxin",
                    name = "会员中心",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll2
                };
                button.Add(btn);

                #endregion
                #region 菜单三 惠旅游
                Button Menu3SubBtn1 = new Button()
                {
                    key = "aboutus",
                    name = "关于我们",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/AboutUs.aspx"
                };
                Button Menu3SubBtn2 = new Button()
                {
                    key = "appdown",
                    name = "APP下载",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/DownApp.aspx"
                };
                Button Menu3SubBtn3 = new Button()
                {
                    key = "recommend",
                    name = "客服反馈",
                    sub_button = null,
                    type = "click",
                    url = "http://www.4008005216.com/AppPage/weixin/Recommend.aspx"
                };

                Button Menu3SubBtn4 = new Button()
                {
                    key = "weimingpian",
                    name = "我的频道",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/huiyuanweixin/mingpian.aspx"
                };

                Button Menu3SubBtn5 = new Button()
                {
                    key = "lvyouguwen",
                    name = "旅游顾问",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/huiyuanweixin/lvyouguwen.aspx"
                };

                List<Button> subBtnAll3 = new List<Button>();
                subBtnAll3.Add(Menu3SubBtn1);
                subBtnAll3.Add(Menu3SubBtn2);
                subBtnAll3.Add(Menu3SubBtn3);

                subBtnAll3.Add(Menu3SubBtn4);
                subBtnAll3.Add(Menu3SubBtn5);

                btn = new Button()
                {
                    key = "menu3",
                    name = "旅游频道",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll3
                };
                button.Add(btn);
                #endregion
                menu.button = button;
                MenuGroup mg = new MenuGroup()
                {
                    menu = menu
                };
                string postData = mg.ToJsonString();
                CreateMenuRequest createRequest = new CreateMenuRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    SendData = postData
                };
                CreateMenuResponse createResponse = mpClient.Execute(createRequest);
                if (createResponse.IsError)
                {
                    rv.ResultMsg = "创建菜单失败,错误信息为:" + createResponse.ErrInfo.ErrCode + "-" + createResponse.ErrInfo.ErrMsg;
                    return rv;
                }
                else
                {
                    rv.IsResult = true;
                    rv.ResultMsg = "创建成功";
                    return rv;
                }
            }
        }
Example #38
0
File: WinXin.cs Project: uwitec/O2O
 /// <summary>
 /// 取得菜单
 /// </summary>
 /// <returns></returns>
 public static List<Button> GetMenu()
 {
     //取得菜单信息
     IMpClient mpClient = new MpClient();
     AccessTokenGetRequest request = new AccessTokenGetRequest()
     {
         AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
     };
     AccessTokenGetResponse response = mpClient.Execute(request);
     if (response.IsError)
     {
         return null;
     }
     else
     {
         GetMenuRequest getRequest = new GetMenuRequest()
         {
             AccessToken = response.AccessToken.AccessToken
         };
         var getResponse = mpClient.Execute(getRequest);
         if (getResponse.IsError)
         {
             return null;
         }
         else
         {
             var m = getResponse.Menu.menu.button;
             return m;
         }
     }
 }
Example #39
0
File: WinXin.cs Project: uwitec/O2O
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="OpenId">用户OpenId</param>
        /// <returns></returns>
        public static User GetUserInfo(string OpenId)
        {
            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                return null;
            }

            GetUserInfoRequest request2 = new GetUserInfoRequest()
            {
                AccessToken = response.AccessToken.AccessToken,
                OpenId = OpenId,
            };

            var response2 = mpClient.Execute(request2);
            if (response2.IsError)
            {
                return null;
            }
            else
            {
                return response2.UserInfo;
            }
        }
Example #40
0
 /// <summary>
 /// 发送客服信息
 /// </summary>
 /// <param name="accessToken">调用凭据</param>
 /// <param name="msg">客服消息</param>
 /// <returns></returns>
 public static SendCustomMessageResponse SendCustomMessage(string accessToken, CustomMessage msg)
 {
     IMpClient mpClient = new MpClient();
     SendCustomMessageRequest request = new SendCustomMessageRequest()
     {
         AccessToken = accessToken,
         SendData = msg.ToJsonString()
     };
     SendCustomMessageResponse response = mpClient.Execute(request);
     return response;
 }
Example #41
0
        /// <summary>
        /// 发送被动响应语音消息
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="fromUserName">发送方</param>
        /// <param name="toUserName">接收方</param>
        /// <param name="voicePath">语音文件路径(支持AMR\MP3,最大256K,播放长度不超过60s)</param>
        /// <returns>是否成功</returns>
        public static bool SendVoiceReplyMessage(string accessToken, string fromUserName, string toUserName, string voicePath)
        {
            IMpClient mpClient = new MpClient();
            UploadMediaRequest request = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type = "voice",
                FileName = voicePath
            };

            UploadMediaResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                return false;
            }
            else
            {
                VoiceReplyMessage msg = new VoiceReplyMessage()
                {
                    CreateTime = Tools.ConvertDateTimeInt(DateTime.Now),
                    FromUserName = fromUserName,
                    ToUserName = toUserName,
                    MediaId = response.MediaId
                };
                System.Web.HttpContext.Current.Response.Write(msg.ToXmlString());
                return true;
            }
        }
Example #42
0
        /// <summary>
        /// 发送语音客服信息
        /// </summary>
        /// <param name="accessToken">调用凭据</param>
        /// <param name="toUser">接收方</param>
        /// <param name="voicePath">语音文件路径</param>
        /// <returns></returns>
        public static SendCustomMessageResponse SendVoiceCustomMessage(string accessToken, string toUser, string voicePath)
        {
            IMpClient mpClient = new MpClient();
            UploadMediaRequest request = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type = "voice",
                FileName = voicePath
            };

            UploadMediaResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                SendCustomMessageResponse response2 = new SendCustomMessageResponse()
                {
                    Body = response.Body,
                    ErrInfo = response.ErrInfo,
                    ReqUrl = response.ReqUrl
                };
                return response2;
            }
            VoiceCustomMessage msg = new VoiceCustomMessage()
            {
                AccessToken = accessToken,
                MediaId = response.MediaId,
                MsgType = "voice",
                ToUser = toUser
            };
            return SendCustomMessage(accessToken, msg);
        }
Example #43
0
        /// <summary>
        /// 发送被动响应音乐消息
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="fromUserName">发送方</param>
        /// <param name="toUserName">接收方</param>
        /// <param name="title">标题</param>
        /// <param name="description">描述</param>
        /// <param name="musicUrl">音乐链接</param>
        /// <param name="hqMusicUrl">高质量音乐链接</param>
        /// <param name="thumbMediaFilePath">缩略图文件路径(64KB,支持JPG格式 )</param>
        /// <returns>是否成功</returns>
        public static bool SendMusicReplyMessage(string accessToken, string fromUserName, string toUserName, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaFilePath)
        {
            IMpClient mpClient = new MpClient();
            UploadMediaRequest request = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type = "thumb",
                FileName = thumbMediaFilePath
            };

            UploadMediaResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                return false;
            }
            else
            {
                MusicReplyMessage msg = new MusicReplyMessage()
                {
                    CreateTime = Tools.ConvertDateTimeInt(DateTime.Now),
                    FromUserName = fromUserName,
                    ToUserName = toUserName,
                    Description = description,
                    Title = title,
                    ThumbMediaId = response.MediaId,
                    HQMusicUrl = hqMusicUrl,
                    MusicURL = musicUrl
                };
                System.Web.HttpContext.Current.Response.Write(msg.ToXmlString());
                return true;
            }
        }
Example #44
0
        /// <summary>
        /// 发送音乐客服信息
        /// </summary>
        /// <param name="accessToken">调用凭据</param>
        /// <param name="toUser">接收方</param>
        /// <param name="title">音乐标题</param>
        /// <param name="description">音乐描述</param>
        /// <param name="musicUrl">音乐地址</param>
        /// <param name="hqMusicUrl">高质量音乐地址</param>
        /// <param name="thumbMediaFilePath">音乐缩略图路径</param>
        /// <returns></returns>
        public static SendCustomMessageResponse SendMusicCustomMessage(string accessToken, string toUser, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaFilePath)
        {
            IMpClient mpClient = new MpClient();
            UploadMediaRequest request = new UploadMediaRequest()
            {
                AccessToken = accessToken,
                Type = "thumb",
                FileName = thumbMediaFilePath
            };

            UploadMediaResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                SendCustomMessageResponse response2 = new SendCustomMessageResponse()
                {
                    Body = response.Body,
                    ErrInfo = response.ErrInfo,
                    ReqUrl = response.ReqUrl
                };
                return response2;
            }
            MusicCustomMessage msg = new MusicCustomMessage()
            {
                AccessToken = accessToken,
                ThumbMediaId = response.MediaId,
                HqMusicUrl = hqMusicUrl,
                MusicUrl = musicUrl,
                MsgType = "music",
                ToUser = toUser,
                Description = description,
                Title = title
            };
            return SendCustomMessage(accessToken, msg);
        }