コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: WinXin.cs プロジェクト: ichoukou/yhq
        /// <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);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <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);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <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));
            }
        }
コード例 #6
0
ファイル: WinXin.cs プロジェクト: ichoukou/yhq
        /// <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);
                }
            }
        }
コード例 #7
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));
        }
コード例 #8
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));
        }
コード例 #9
0
ファイル: sync_weixin_yonghu.aspx.cs プロジェクト: uwitec/O2O
        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("获取关注者列表成功");
        }
コード例 #10
0
        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));
        }
コード例 #11
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);
            }
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <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("发送成功");
            }
        }
コード例 #13
0
ファイル: API.ashx.cs プロジェクト: sd009896/CustomerMall
        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);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <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("发送成功");
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <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("发送成功");
            }
        }
コード例 #16
0
ファイル: CustomMsgBack.aspx.cs プロジェクト: ichoukou/yhq
        /// <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();
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <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("发送成功");
            }
        }
コード例 #18
0
ファイル: WinXin.cs プロジェクト: ichoukou/yhq
        /// <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"));
            }
        }
コード例 #19
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);
        }
コード例 #20
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);
            }
        }
コード例 #21
0
ファイル: WxChatHelper.cs プロジェクト: songjiang1/www.public
        /// <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);
        }
コード例 #22
0
ファイル: WinXin.cs プロジェクト: ichoukou/yhq
 /// <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);
     }
 }
コード例 #23
0
ファイル: CustomMsgBack.aspx.cs プロジェクト: uwitec/O2O
        /// <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();
        }
コード例 #24
0
ファイル: WinXin.cs プロジェクト: 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;

            }
        }
コード例 #25
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);
            }
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
        public static string GetCreativeList()
        {
            string    type     = "news";
            int       offset   = 0;
            int       count    = 1;
            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);
            }

            MaterialList materialList = new MaterialList
            {
                Type   = type,
                Offset = offset,
                Count  = count
            };

            var requestUpload = new GetMaterialListRequest
            {
                AccessToken = response.AccessToken.AccessToken,
                SendData    = materialList.ToJsonString()
            };
            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));
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <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(); //查询一把,显示一下信息
            }
        }
コード例 #29
0
        public static string OpenIdMessageMethod()
        {
            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);
            }

            string openid = "\"oIXLKvpVPUpvQ7yR2mLSgNer-K5Y\",\"oIXLKvh_-HrDq8KHULTJ99mIHbMA\"";
            OpenIdMessageInterface permanent = new OpenIdMessageInterface
            {
                MediaId = "9onupBukQHhG1T8Pvkau1D4KK6igthNYMPykga803f7j3YvNvawzv5qeZyjEndkA",
                Title   = "测试标题2",
                Msgtype = "mpnews",
                Touser  = openid
            };

            var requestUpload = new OpenIdMessageInterfaceRequest
            {
                AccessToken = response.AccessToken.AccessToken,
                SendData    = permanent.ToCreateJsonString()
            };
            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));
        }
コード例 #30
0
        public static string BulkMessagePacketMethod()
        {
            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);
            }
            PacketInterfaceMessage permanent = new PacketInterfaceMessage
            {
                MediaId = "9onupBukQHhG1T8Pvkau1D4KK6igthNYMPykga803f7j3YvNvawzv5qeZyjEndkA",
                Title   = "测试标题1",
                IsToAll = "false",
                GroupId = 101,
                Msgtype = "mpnews"
            };

            var requestUpload = new GraphicInterfaceMessageRequest
            {
                AccessToken = response.AccessToken.AccessToken,
                SendData    = permanent.ToCreateJsonString()
            };
            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));
        }
コード例 #31
0
        /// <summary>
        /// 移动用户分组测试
        /// </summary>
        public static void SetUserGroup(string userId, string groupId)
        {
            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 request2 = new SetUserGroupRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    UserId      = userId,
                    ToGroupId   = groupId
                };

                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);
            }
        }
コード例 #32
0
ファイル: Program.cs プロジェクト: ludycool/WeiXinF
        /// <summary>
        /// 创建分组测试
        /// </summary>
        public static void CreateGroupTest()
        {
            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 msg = new Group()
            {
                name = "分组一"
            };

            CreateGroupRequest createRequest = new CreateGroupRequest()
            {
                AccessToken = response.AccessToken.AccessToken,
                SendData    = msg.ToCreateJsonString()
            };

            var createResponse = mpClient.Execute(createRequest);

            if (createResponse.IsError)
            {
                Console.WriteLine("创建分组失败,错误信息为:" + createResponse.ErrInfo.ErrCode + "-" + createResponse.ErrInfo.ErrMsg);
            }
            else
            {
                Console.WriteLine("创建分组成功,分组ID为:" + createResponse.GroupInfo.id + ",分组名称为:" + createResponse.GroupInfo.name);
            }
        }
コード例 #33
0
        public static string RemarkName(string openid, string name)
        {
            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);
                }

                SetUpUserRemarkName remarkName = new SetUpUserRemarkName
                {
                    AccessToken = response.AccessToken.AccessToken,
                    UserId      = openid,
                    ReamrkName  = name
                };

                var createResponse = mpClient.Execute(remarkName);
                if (createResponse.IsError)
                {
                    LogHelper.WriteLog(typeof(UserManagementOperation), createResponse.ErrInfo.ErrMsg);
                    return(null);
                }
                return(createResponse.ErrMsg);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(UserManagementOperation), ex);
                throw new Exception(ex.Message);
            }
        }
コード例 #34
0
ファイル: MessageHandler.cs プロジェクト: uwitec/O2O
        /// <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;
            }
        }
コード例 #35
0
ファイル: WinXin.cs プロジェクト: 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");
     }
 }
コード例 #36
0
ファイル: WinXin.cs プロジェクト: 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;
                }
            }
        }
コード例 #37
0
ファイル: WinXin.cs プロジェクト: 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;
                }
            }
        }
コード例 #38
0
ファイル: WinXin.cs プロジェクト: 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;
         }
     }
 }
コード例 #39
0
ファイル: WinXin.cs プロジェクト: 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;
            }
        }
コード例 #40
0
ファイル: MessageHandler.cs プロジェクト: uwitec/O2O
 /// <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;
 }
コード例 #41
0
ファイル: MessageHandler.cs プロジェクト: uwitec/O2O
        /// <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);
        }
コード例 #42
0
ファイル: MessageHandler.cs プロジェクト: uwitec/O2O
        /// <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;
            }
        }
コード例 #43
0
ファイル: MessageHandler.cs プロジェクト: uwitec/O2O
        /// <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);
        }