Exemple #1
0
        public override AbstractResponse OnTextRequest(TextRequest textRequest)
        {
            WeiXinHelper.UpdateRencentOpenID(textRequest.FromUserName);
            AbstractResponse keyResponse = this.GetKeyResponse(textRequest.Content, textRequest);

            if (keyResponse != null)
            {
                return(keyResponse);
            }
            IList <Hidistro.Entities.VShop.ReplyInfo> replies = ReplyHelper.GetReplies(ReplyType.Keys);

            if ((replies == null) || ((replies.Count == 0) && this.IsOpenManyService()))
            {
                this.GotoManyCustomerService(textRequest);
            }
            foreach (Hidistro.Entities.VShop.ReplyInfo info in replies)
            {
                if ((info.MatchType == MatchType.Equal) && (info.Keys == textRequest.Content))
                {
                    AbstractResponse response = this.GetResponse(info, textRequest.FromUserName);
                    response.ToUserName   = textRequest.FromUserName;
                    response.FromUserName = textRequest.ToUserName;
                    return(response);
                }
                if ((info.MatchType == MatchType.Like) && info.Keys.Contains(textRequest.Content))
                {
                    AbstractResponse response3 = this.GetResponse(info, textRequest.FromUserName);
                    response3.ToUserName   = textRequest.FromUserName;
                    response3.FromUserName = textRequest.ToUserName;
                    return(response3);
                }
            }
            return(this.DefaultResponse(textRequest));
        }
Exemple #2
0
        /// <summary>
        /// 使用微信模板发送固定消息
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>结果</returns>
        public JResult SendMessage(SendMessageRequest request)
        {
            var result = new JResult();

            try
            {
                var strToken = GetAccessToken(request.WeiXinAppId, request.WeiXinAppSecret);

                if (!strToken.Status)
                {
                    throw new Exception(strToken.Message);
                }

                var wResult = WeiXinHelper.SendTemplateMessage(strToken.Data, request.OpenId, request.TemplateId, request.Data, request.Url);

                if (wResult.IsErr)
                {
                    throw new Exception(wResult.ErrMsg);
                }

                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return(result);
        }
        //protected IUserRepository<UserDTO> userRepository = RepositoryFactory.GetInstance().GetUserRepository();
        //protected IAuthProfileRepository<AuthProfileDTO> authProfileRepository = RepositoryFactory.GetInstance().GetAuthProfileRepository();

        public string Handle_LocationEventMessage(LocationMessage message)
        {
            //回复欢迎消息
            TextMessage tm = new TextMessage();

            tm.ToUserName   = message.FromUserName;
            tm.FromUserName = message.ToUserName;
            tm.CreateTime   = WeiXinHelper.GetNowTime();
            //tm.Content = string.Format("您当前的经度:{0}, 纬度{1}",message.Longitude, message.Latitude);

            string url     = string.Format("http://lbs.juhe.cn/api/getaddressbylngb?lngx={0}&lngy={1}", message.Longitude, message.Latitude);
            string content = HttpUtility.SendGetHttpRequest(url, "text/json");
            //Log4netHelper.Write("content from web: " + content);

            JsonTextReader       tr          = new JsonTextReader(new StringReader(content));
            JsonSerializer       jSerializer = new JsonSerializer();
            LocationSearchResult rObj        = jSerializer.Deserialize <LocationSearchResult>(tr);

            //Log4netHelper.Write("resultinfo: " + rObj.resultinfo);
            //Log4netHelper.Write("formatted_address: " + rObj.row.result.formatted_address);

            //Log4netHelper.Write("Handle_LocationEventMessage content: " + content);
            tm.Content = string.Format("您当前的位置为:{0}", rObj.row.result.formatted_address);
            string returnValue = tm.GetResponseString();

            return(returnValue);
        }
Exemple #4
0
        public GetAccessTokenResult GetAccessToken(string appId, string appSecret)
        {
            var cacheKey = appId;

            if (IGetAccessTokenCache != null)
            {
                var cacheObj = IGetAccessTokenCache.Get(cacheKey);
                if (ToolFactory.CreateIValidatorTool().IsNotEmpty(cacheObj))
                {
                    return(cacheObj);
                }
            }
            string url    = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appId, appSecret);
            var    client = ToolFactory.Ioc.Get <IHttpClient>();
            var    result = client.DownloadToString(url);

            if (WeiXinHelper.IsFailureInvokeWeiXinAPI(result))
            {
                throw new Exception(result);
            }
            var iJson       = ToolFactory.CreateIJsonSerializeTool();
            var accessToken = iJson.DeserializeFromString <GetAccessTokenResult>(result);

            if (IGetAccessTokenCache != null)
            {
                IGetAccessTokenCache.Set(cacheKey, accessToken);
            }
            return(accessToken);
        }
Exemple #5
0
        /// <summary>
        /// App 预支付
        /// </summary>
        /// <returns></returns>
        public ActionResult AppPrePay()
        {
            string orderNo     = "";       //订单编号,文档中的out_trade_no
            string description = "";       //订单详情
            string totalFee    = "";       //订单金额(单位:分)
            string notifyUrl   = "";       //支付通知Url
            string createIp    = "";       //用户IP

            string traceId = string.Empty; //

            WxPayModel model = WxPayModel.Create(description, orderNo, totalFee, notifyUrl, createIp);

            var result = WeiXinHelper.PreWXPay(model.CreateAppPrePayPackage(traceId));

            if (!string.IsNullOrEmpty(result.PrePayId))
            {
                Response.Write("预支付ID:" + result.PrePayId);
            }
            else
            {
                Response.Write("预支付失败!");
            }

            return(View());
        }
        public async Task <IActionResult> Seat(string code)
        {
            var settingCode = await SettingManager.GetSettingValueForTenantAsync("Code", 1);

            if (settingCode != code)
            {
                return(Error("此二维码已过期"));
            }

            var weuser = WeiXinHelper.GetWeiXinUserInfo();
            var openId = weuser.openid;

            //如果系统中没有此用户则新增
            var seatuser = new SeatUser()
            {
                OpenId   = openId,
                NickName = weuser.nickname,
                Avata    = weuser.headimgurl
            };

            ViewBag.isFirstTime = !await SeatUserManager.IsNameSet(seatuser);

            ViewBag.openId = openId;
            //ViewBag.openId = "111";
            return(View());
        }
Exemple #7
0
        /// <summary>
        /// 获取jsapi_ticket
        /// jsapi_ticket是公众号用于调用微信JS接口的临时票据。
        /// 正常情况下,jsapi_ticket的有效期为7200秒,通过access_token来获取。
        /// 由于获取jsapi_ticket的api调用次数非常有限,频繁刷新jsapi_ticket会导致api调用受限,影响自身业务,开发者必须在自己的服务全局缓存jsapi_ticket 。
        /// </summary>
        /// <param name="accessToken">微信全局access_token</param>
        /// <returns></returns>
        public GenericExecResult <string> GetJsTickect(string accessToken)
        {
            var cacheJsTickect = _ICache.Get <string>(CacheJsTickectId);

            if (ToolFactory.CreateIValidatorTool().IsNotEmpty(cacheJsTickect))
            {
                return(new GenericExecResult <string>()
                {
                    Success = true,
                    Data = cacheJsTickect
                });
            }
            ;
            var url            = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", accessToken);
            var downloadResult = WeiXinHelper.DownloadToString(url);

            if (WeiXinHelper.IsFailureInvokeWeiXinAPI(downloadResult))
            {
                return(WeiXinHelper.FromDownloadResultToErrorGenericExecResult(downloadResult));
            }
            var jsTicket = WeiXinHelper.ToGetJsTickectResultDto(downloadResult.Data).ticket;

            _ICache.Set(CacheJsTickectId, jsTicket, DateTime.Now.AddSeconds(CacheJsTickectExpireTimeoutSecond));
            return(new GenericExecResult <string>()
            {
                Success = true,
                Data = jsTicket
            });
        }
Exemple #8
0
        public static int LoginSuccess(IWxUsersRepository repository, IWxFriendsRepository wxFriendsRepository,
                                       HttpResponse Response, IAuthCore authcore, string uuid, string tip, ref string url)
        {
            var status = WeiXinHelper.GetLoginStatus(uuid, tip, ref url);

            return(status);
        }
Exemple #9
0
        public override AbstractResponse OnTextRequest(TextRequest textRequest)
        {
            WeiXinHelper.UpdateRencentOpenID(textRequest.FromUserName);
            AbstractResponse keyResponse = this.GetKeyResponse(textRequest.Content, textRequest);

            if (keyResponse != null)
            {
                return(keyResponse);
            }
            System.Collections.Generic.IList <Hidistro.Entities.VShop.ReplyInfo> replies = ReplyHelper.GetReplies(ReplyType.Keys);
            if (replies == null || (replies.Count == 0 && this.IsOpenManyService()))
            {
                this.GotoManyCustomerService(textRequest);
            }
            foreach (Hidistro.Entities.VShop.ReplyInfo current in replies)
            {
                if (current.MatchType == MatchType.Equal && current.Keys == textRequest.Content)
                {
                    AbstractResponse response = this.GetResponse(current, textRequest.FromUserName);
                    response.ToUserName   = textRequest.FromUserName;
                    response.FromUserName = textRequest.ToUserName;
                    AbstractResponse result = response;
                    return(result);
                }
                if (current.MatchType == MatchType.Like && current.Keys.Contains(textRequest.Content))
                {
                    AbstractResponse response2 = this.GetResponse(current, textRequest.FromUserName);
                    response2.ToUserName   = textRequest.FromUserName;
                    response2.FromUserName = textRequest.ToUserName;
                    AbstractResponse result = response2;
                    return(result);
                }
            }
            return(this.DefaultResponse(textRequest));
        }
Exemple #10
0
        /// <summary>
        /// 获取登陆二维码
        /// </summary>
        /// <param name="uuid"></param>
        /// <returns></returns>
        public static WxLoginQrCodeDto GetWxLoginQrCode()
        {
            var uuid = WeiXinHelper.GetWxUid();
            var url  = WeiXinHelper.WxQrCodeUrl(uuid);

            return(WxLoginQrCodeDto.GetQrCodeDto(uuid, url));
        }
Exemple #11
0
        /// <summary>
        /// 创建账套管理员用户
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="registerDto"></param>
        /// <returns></returns>
        private async Task <User> CreateTenantAdminUser(int tenantId, RegisterDto registerDto)
        {
            var user = new User()
            {
                TenantId    = tenantId,
                UserName    = registerDto.Mobile,
                Name        = registerDto.Name,
                Password    = SimpleStringCipher.Instance.Encrypt(registerDto.Password),
                PhoneNumber = registerDto.Mobile
            };
            //同时绑定微信
            var weuser = WeiXinHelper.GetWeiXinUserInfo();

            if (weuser != null)
            {
                user.Logins = new List <UserLogin>
                {
                    new UserLogin
                    {
                        LoginProvider = WeChatAuthProviderApi.Name,
                        ProviderKey   = weuser.openid,
                        TenantId      = user.TenantId
                    }
                };
            }

            await UserManager.InsertAsync(user);

            await CurrentUnitOfWork.SaveChangesAsync(); // To get admin user's id

            return(user);
        }
Exemple #12
0
        //
        // GET: /UserInfo/

        public ActionResult Index()
        {
            #region 应用授权作用域,snsapi_base

            //授权获取到的code
            string code = "";
            //通过code获取用户信息 不需要关注公众号
            WeiXinUserSampleInfo sampleInfo = WeiXinHelper.GetUserSampleInfo(code);
            string openId = sampleInfo.OpenId;

            #endregion

            #region (思路一致,开发过程中没用到,暂时放空。。)snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息)

            //授权获取到的code
            string code2 = "";
            //通过code获取用户信息 不需要关注公众号
            WeiXinUserSampleInfo sampleInfo2 = WeiXinHelper.GetUserSampleInfo(code2);
            string openId2     = sampleInfo2.OpenId;
            string accessToken = sampleInfo2.Access_Token;

            //todo:刷新accessToken 获取 refresh_token(如果需要)

            //todo:获取用户信息


            #endregion

            //这种方法获取用户信息,需要用户关注公众号
            WeiXinUserInfo info = WeiXinHelper.GetUserInfo(openId);

            return(View());
        }
Exemple #13
0
        public override AbstractResponse OnEvent_ClickRequest(ClickEventRequest clickEventRequest)
        {
            WeiXinHelper.UpdateRencentOpenID(clickEventRequest.FromUserName);
            Hidistro.Entities.VShop.MenuInfo menu = VShopHelper.GetMenu(Convert.ToInt32(clickEventRequest.EventKey));
            if (menu == null)
            {
                return(null);
            }
            Hidistro.Entities.VShop.ReplyInfo reply = ReplyHelper.GetReply(menu.ReplyId);
            if (reply == null)
            {
                return(null);
            }
            AbstractResponse keyResponse = this.GetKeyResponse(reply.Keys, clickEventRequest);

            if (keyResponse != null)
            {
                return(keyResponse);
            }
            AbstractResponse response = this.GetResponse(reply, clickEventRequest.FromUserName);

            if (response == null)
            {
                this.GotoManyCustomerService(clickEventRequest);
            }
            response.ToUserName   = clickEventRequest.FromUserName;
            response.FromUserName = clickEventRequest.ToUserName;
            return(response);
        }
Exemple #14
0
        public string GetResponseString()
        {
            CreateTime = WeiXinHelper.GetNowTime();
            string returnValue = this.ToXML().ToString().Replace("&lt;", "<").Replace("&gt;", ">");

            return(returnValue);
        }
        public ActionResult Select()
        {
            string menuString = WeiXinHelper.GetMenu();

            Response.Write(menuString);

            return(View());
        }
Exemple #16
0
        /// <summary>
        /// 订单退款
        /// </summary>
        /// <param name="transaction_Id">微信交易单号</param>
        /// <param name="orderNo">我们自己的单号</param>
        /// <param name="totalFee">订单金额(分)</param>
        /// <param name="refundNo">退款单号(我们自己定义)</param>
        /// <param name="refundFee">退款金额(分)</param>
        /// <returns></returns>
        public bool UnifiedOrderRefund(string transaction_Id, string orderNo, string totalFee, string refundNo, string refundFee)
        {
            UnifiedWxPayModel model    = UnifiedWxPayModel.CreateUnifiedModel(WeiXinConst.AppId, WeiXinConst.PartnerId, WeiXinConst.PartnerKey);
            string            postData = model.CreateOrderRefundXml(orderNo, transaction_Id, totalFee, refundNo, refundFee);

            //退款需要用到证书, 要配置WeiXineConst CertPath 和 CertPwd
            return(WeiXinHelper.Refund(postData, WeiXinConst.CertPath, WeiXinConst.CertPwd));
        }
Exemple #17
0
        public override AbstractResponse OnEvent_SubscribeRequest(SubscribeEventRequest subscribeEventRequest)
        {
            string text = "";

            if (subscribeEventRequest.EventKey != null)
            {
                text = subscribeEventRequest.EventKey;
            }
            if (text.Contains("qrscene_"))
            {
                text = text.Replace("qrscene_", "").Trim();
                if (text == "1")
                {
                    if (WeiXinHelper.BindAdminOpenId.Count > 10)
                    {
                        WeiXinHelper.BindAdminOpenId.Clear();
                    }
                    if (WeiXinHelper.BindAdminOpenId.ContainsKey(subscribeEventRequest.Ticket))
                    {
                        WeiXinHelper.BindAdminOpenId[subscribeEventRequest.Ticket] = subscribeEventRequest.FromUserName;
                    }
                    else
                    {
                        WeiXinHelper.BindAdminOpenId.Add(subscribeEventRequest.Ticket, subscribeEventRequest.FromUserName);
                    }
                    return(new TextResponse
                    {
                        CreateTime = System.DateTime.Now,
                        Content = "您正在扫描尝试绑定管理员身份,身份已识别",
                        ToUserName = subscribeEventRequest.FromUserName,
                        FromUserName = subscribeEventRequest.ToUserName
                    });
                }
                ScanInfos scanInfosByTicket = ScanHelp.GetScanInfosByTicket(subscribeEventRequest.Ticket);
                Globals.Debuglog(text + ":" + subscribeEventRequest.Ticket, "_Debuglog.txt");
                if (!MemberProcessor.IsExitOpenId(subscribeEventRequest.FromUserName) && scanInfosByTicket != null && scanInfosByTicket.BindUserId > 0)
                {
                    this.CreatMember(subscribeEventRequest.FromUserName, scanInfosByTicket.BindUserId);
                    ScanHelp.updateScanInfosLastActiveTime(System.DateTime.Now, scanInfosByTicket.Sceneid);
                }
            }
            WeiXinHelper.UpdateRencentOpenID(subscribeEventRequest.FromUserName);
            Hidistro.Entities.VShop.ReplyInfo subscribeReply = ReplyHelper.GetSubscribeReply();
            if (subscribeReply == null)
            {
                return(null);
            }
            subscribeReply.Keys = "登录";
            AbstractResponse response = this.GetResponse(subscribeReply, subscribeEventRequest.FromUserName);

            if (response == null)
            {
                this.GotoManyCustomerService(subscribeEventRequest);
            }
            response.ToUserName   = subscribeEventRequest.FromUserName;
            response.FromUserName = subscribeEventRequest.ToUserName;
            return(response);
        }
Exemple #18
0
        public override AbstractResponse OnEvent_MassendJobFinishEventRequest(MassendJobFinishEventRequest massendJobFinishEventRequest)
        {
            string returnjsondata = string.Concat(new object[] { "公众号的微信号(加密的):", massendJobFinishEventRequest.ToUserName, ",发送完成时间:", massendJobFinishEventRequest.CreateTime, ",过滤通过条数:", massendJobFinishEventRequest.FilterCount, ",发送失败的粉丝数:", massendJobFinishEventRequest.ErrorCount });

            switch (massendJobFinishEventRequest.Status)
            {
            case "send success":
                returnjsondata = returnjsondata + "(发送成功)";
                break;

            case "send fail":
                returnjsondata = returnjsondata + "(发送失败)";
                break;

            case "err(10001)":
                returnjsondata = returnjsondata + "(涉嫌广告)";
                break;

            case "err(20001)":
                returnjsondata = returnjsondata + "(涉嫌政治)";
                break;

            case "err(20004)":
                returnjsondata = returnjsondata + "(涉嫌社会)";
                break;

            case "err(20002)":
                returnjsondata = returnjsondata + "(涉嫌色情)";
                break;

            case "err(20006)":
                returnjsondata = returnjsondata + "(涉嫌违法犯罪)";
                break;

            case "err(20008)":
                returnjsondata = returnjsondata + "(涉嫌欺诈)";
                break;

            case "err(20013)":
                returnjsondata = returnjsondata + "(涉嫌版权)";
                break;

            case "err(22000)":
                returnjsondata = returnjsondata + "(涉嫌互相宣传)";
                break;

            case "err(21000)":
                returnjsondata = returnjsondata + "(涉嫌其他)";
                break;

            default:
                returnjsondata = returnjsondata + "(" + massendJobFinishEventRequest.Status + ")";
                break;
            }
            WeiXinHelper.UpdateMsgId(0, massendJobFinishEventRequest.MsgId.ToString(), (massendJobFinishEventRequest.Status == "send success") ? 1 : 2, Globals.ToNum(massendJobFinishEventRequest.SentCount), Globals.ToNum(massendJobFinishEventRequest.TotalCount), returnjsondata);
            return(null);
        }
        //
        // GET: /Menu/


        public ActionResult Create()
        {
            string menuFile   = Server.MapPath("~/Document/menu.txt");
            string menuString = System.IO.File.ReadAllText(menuFile);

            ErrorMessage message = WeiXinHelper.CreateMenu(menuString);

            return(View(message));
        }
Exemple #20
0
        //
        // GET: /GeoCoder/

        public ActionResult Index()
        {
            //需配置 WeiXineConst的BaiduAk
            string lat   = "31.1430";  //经度
            string lng   = "121.2943"; // 纬度
            var    model = WeiXinHelper.GeoCoder(lat, lng);

            return(View(model));
        }
Exemple #21
0
        /// <summary>
        /// 到微信服务器查询 订单支付的结果 (jsapi支付返回ok,我们要判断下服务器支付状态,如果没有支付成功,到微信服务器查询)
        /// </summary>
        /// <param name="orderNo"></param>
        public bool QueryOrder(string orderNo)
        {
            //这里应先判断服务器 订单支付状态,如果接到通知,并已经支付成功,就不用 执行下面的查询了
            UnifiedWxPayModel        model   = UnifiedWxPayModel.CreateUnifiedModel(WeiXinConst.AppId, WeiXinConst.PartnerId, WeiXinConst.PartnerKey);
            UnifiedOrderQueryMessage message = WeiXinHelper.UnifiedOrderQuery(model.CreateOrderQueryXml(orderNo));

            //此处主动查询的结果,只做查询用(不能作为支付成功的依据)
            return(message.Success);
        }
Exemple #22
0
 /// <summary>
 /// 此处会创建新的Token返回,只有在调用接口提示AccessToken过期时 才调用这个接口。
 /// </summary>
 /// <returns></returns>
 public static AccessToken CreateNewInstance()
 {
     lock (lock_Object)
     {
         _Token.CreateTime = DateTime.Now;
         _Token.CopyModel(JsonConvert.DeserializeObject <AccessToken>(WeiXinHelper.GetAccessToken()));
     }
     return(_Token);
 }
        //protected string HandleLoginClickAndGetResponse(EventMessage message)
        //{
        //    TextMessage tm = new TextMessage();
        //    tm.ToUserName = message.FromUserName;
        //    tm.FromUserName = message.ToUserName;
        //    tm.CreateTime = WeiXinHelper.GetNowTime();
        //    tm.Content = AuthUtility.GetAuthResult(message);

        //    string returnValue = tm.GetResponseString();

        //    return returnValue;
        //}

        //private string HandleLogoutClickAndGetResponse(EventMessage message)
        //{
        //    TextMessage tm = new TextMessage();
        //    tm.ToUserName = message.FromUserName;
        //    tm.FromUserName = message.ToUserName;
        //    tm.CreateTime = WeiXinHelper.GetNowTime();
        //    tm.Content = AuthUtility.GetLogoutResult(message);

        //    string returnValue = tm.GetResponseString();

        //    return returnValue;
        //}

        private string HandleOutlineClickAndGetResponse(MenuEventMessage message)
        {
            TuwenMessage twMsg = new TuwenMessage();

            twMsg.FromUserName = message.ToUserName;
            twMsg.ToUserName   = message.FromUserName;
            twMsg.CreateTime   = WeiXinHelper.GetNowTime();

            TuwenArticleMessage article1 = new TuwenArticleMessage()
            {
                Title       = "交大红娘团队",
                Description = "交大红娘团队成员有吴斯一, 陈楠,石皓,刘崇宵",
                PicUrl      = "http://img.taopic.com/uploads/allimg/130716/318769-130G60Q62985.jpg",
                Url         = "http://img.taopic.com/uploads/allimg/130716/318769-130G60Q62985.jpg"
            };

            TuwenArticleMessage article2 = new TuwenArticleMessage()
            {
                Title       = "吴斯一,CEO",
                Description = "吴斯一,CEO",
                PicUrl      = "http://e.hiphotos.baidu.com/image/h%3D200/sign=9e12075d6e224f4a4899741339f69044/d1a20cf431adcbef5ae00f7dafaf2edda2cc9ff0.jpg",
                Url         = "http://e.hiphotos.baidu.com/image/h%3D200/sign=9e12075d6e224f4a4899741339f69044/d1a20cf431adcbef5ae00f7dafaf2edda2cc9ff0.jpg"
            };

            TuwenArticleMessage article3 = new TuwenArticleMessage()
            {
                Title       = "陈楠,CTO",
                Description = "陈楠,CTO",
                PicUrl      = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg",
                Url         = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg"
            };

            TuwenArticleMessage article4 = new TuwenArticleMessage()
            {
                Title       = "石皓,CFO",
                Description = "石皓,CFO",
                PicUrl      = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg",
                Url         = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg"
            };

            TuwenArticleMessage article5 = new TuwenArticleMessage()
            {
                Title       = "刘崇宵,COO",
                Description = "刘崇宵,COO",
                PicUrl      = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg",
                Url         = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg"
            };

            twMsg.AddArticle(article1);
            twMsg.AddArticle(article2);
            twMsg.AddArticle(article3);
            twMsg.AddArticle(article4);
            twMsg.AddArticle(article5);

            return(twMsg.GetResponseString());
        }
Exemple #24
0
        /// <summary>
        /// 用户信息接口
        /// </summary>
        /// <param name="weixinAppId">微信AppId</param>
        /// <param name="weixinAppSecret">微信AppSecret</param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public WXUserInfo GetUserInfo(string weixinAppId, string weixinAppSecret, string openId)
        {
            var response = GetAccessToken(weixinAppId, weixinAppSecret);

            if (response.Status)
            {
                return(WeiXinHelper.GetUserInfo(response.Data, openId));
            }
            return(null);
        }
Exemple #25
0
        /// <summary>
        /// 绑定提醒人至策略
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual async Task BindReminder(int id)
        {
            var manager = Manager as TacticManager;
            var weuser  = WeiXinHelper.GetWeiXinUserInfo();
            var person  = await PersonManager.GetPersonByWeUserOrInsert(weuser);

            var tactic = await manager.Repository.GetAll().IgnoreQueryFilters().Where(o => o.Id == id).SingleOrDefaultAsync();

            await manager.AddReminderToTactic(tactic, person);
        }
Exemple #26
0
        //
        // GET: /V3Jsapi/


        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionResult Pay()
        {
            string code        = "";                               //网页授权获得的code
            string orderNo     = "";                               //文档中的out_trade_no
            string description = "";                               //商品描述
            string totalFee    = "1";                              //订单金额(单位:分)
            string createIp    = "127.0.0.1";
            string notifyUrl   = "";                               //通知url
            string openId      = WeiXinHelper.GetUserOpenId(code); //通过网页授权code获取用户openid(或者之前有存储用户的openid 也可以直接拿来用)

            //prepayid 只有第一次支付时生成,如果需要再次支付,必须拿之前生成的prepayid。
            //也就是说一个orderNo 只能对应一个prepayid
            string prepayid = string.Empty;

            #region 之前生成过 prepayid,此处可略过

            //创建Model
            UnifiedWxPayModel model = UnifiedWxPayModel.CreateUnifiedModel(WeiXinConst.AppId, WeiXinConst.PartnerId, WeiXinConst.PartnerKey);

            //预支付
            UnifiedPrePayMessage result = WeiXinHelper.UnifiedPrePay(model.CreatePrePayPackage(description, orderNo, totalFee, createIp, notifyUrl, openId));

            if (result == null ||
                !result.ReturnSuccess ||
                !result.ResultSuccess ||
                string.IsNullOrEmpty(result.Prepay_Id))
            {
                throw new Exception("获取PrepayId 失败");
            }

            //预支付订单
            prepayid = result.Prepay_Id;

            #endregion

            //JSAPI 支付参数的Model
            PayModel payModel = new PayModel()
            {
                AppId     = model.AppId,
                Package   = string.Format("prepay_id={0}", prepayid),
                Timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(),
                Noncestr  = CommonUtil.CreateNoncestr(),
            };

            Dictionary <string, string> nativeObj = new Dictionary <string, string>();
            nativeObj.Add("appId", payModel.AppId);
            nativeObj.Add("package", payModel.Package);
            nativeObj.Add("timeStamp", payModel.Timestamp);
            nativeObj.Add("nonceStr", payModel.Noncestr);
            nativeObj.Add("signType", payModel.SignType);
            payModel.PaySign = model.GetCftPackage(nativeObj); //生成JSAPI 支付签名


            return(View(payModel));
        }
Exemple #27
0
        public static bool CheckStatus(HttpResponse httpResponse, string wxHosts, string wxCookie, PassTicketXmlInfo keys, SyncKey syncKey)
        {
            var status = WeiXinHelper.GetWxStatus(wxHosts, wxCookie, keys, syncKey);

            if (!status)
            {
                AuthCore.DeleteUin(httpResponse);
                throw new CustomerException("登录过期,请重新登录", -2);
            }
            return(status);
        }
Exemple #28
0
 public AbstractResponse GotoManyCustomerService(AbstractRequest requestMessage)
 {
     WeiXinHelper.UpdateRencentOpenID(requestMessage.FromUserName);
     if (!this.IsOpenManyService())
     {
         return(null);
     }
     return(new AbstractResponse {
         FromUserName = requestMessage.ToUserName, ToUserName = requestMessage.FromUserName, MsgType = ResponseMsgType.transfer_customer_service
     });
 }
Exemple #29
0
        public WeiXinAccount GetBasicAccountInfo(string accessToken, string openId, string lang = "zh_CN")
        {
            var url    = string.Format(WEIXIN_GET_BASIC_ACCOUNT_INFO_URL, accessToken, openId, lang);
            var client = ToolFactory.Ioc.Get <IHttpClient>();
            var result = client.Get(url);

            WeiXinHelper.IsFailureInvokeWeiXinAPIThrowException(result);
            var modelResult = WeiXinHelper.JsonHelper().DeserializeFromString <WeiXinAccount>(result);

            return(modelResult);
        }
        protected string HandleSubscribeAndGetResponse(EventMessage message)
        {
            //回复欢迎消息
            TextMessage tm = new TextMessage();

            tm.ToUserName   = message.FromUserName;
            tm.FromUserName = message.ToUserName;
            tm.CreateTime   = WeiXinHelper.GetNowTime();
            tm.Content      = "欢迎您关注交大红娘-小鹿心动,我是服务小二,有事就请问我,呵呵!\n\n";
            string returnValue = tm.GetResponseString();

            return(returnValue);
        }