public ResultObj <List <WechatMemberModel> > GetData(string nickName = "", int pageIndex = 1, int pageSize = 10) { // IProduct service = new ProductService(); //List<ProductModel> products = service.GetAllProducts(); WechatMemberModel memberInfo = new WechatMemberModel(); memberInfo.NickName = nickName; memberInfo.PageIndex = pageIndex; memberInfo.PageSize = pageSize; var users = _IBase.GetAll(memberInfo); int totalcount = _IBase.GetCount(memberInfo); var pagination = new Pagination { PageSize = pageSize, PageIndex = pageIndex, StartIndex = 0, TotalRows = totalcount, TotalPage = 0 }; return(Content(users, pagination)); }
public ResultObj <PayStateModel> GetUrl(string m, string code, string retBack = "") { //var log = LogManager.GetLogger("FycnApi", "wechat"); //log.Info("mmmmmmmmmmmmmmmm:"+m); string url = string.Empty; //KeyJsonModel keyJsonInfo = PayHelper.AnalizeKey(k); IPay _ipay = new PayService(); WxPayConfig payConfig = _ipay.GenerateConfigModelWByClientId(m); PayStateModel payState = new PayStateModel(); if (string.IsNullOrEmpty(payConfig.APPID)) { payState.RequestState = "2"; payState.ProductJson = ""; payState.RequestData = ""; return(Content(payState)); } PayModel payInfo = new PayModel(); //JsApi.payInfo = new PayModel(); payInfo.k = m; JsApi jsApi = new JsApi(); string backUrl = "/wechat.html?clientId=" + m; if (!string.IsNullOrEmpty(retBack)) { backUrl = backUrl + HttpUtility.UrlDecode(retBack); } jsApi.GetOpenidAndAccessToken(code, payConfig, payInfo, backUrl, "snsapi_userinfo"); if (string.IsNullOrEmpty(payInfo.openid)) { payState.RequestState = "0"; payState.ProductJson = ""; payState.RequestData = payInfo.redirect_url; return(Content(payState)); } //根据code 返回access_token //string urlAcess = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", payConfig.APPID,payConfig.APPSECRET,code); //string jsonResult = HttpService.Get(urlAcess); //log.Info("access_token:" + jsonResult); //Dictionary<string,string> dicAcess = JsonHandler.GetObjectFromJson<Dictionary<string,string>>(jsonResult); string accessToken = payInfo.access_token;//dicAcess["access_token"]; //取授权用户信息 string urlUserInfo = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", accessToken, payInfo.openid); string jsonUserInfo = HttpService.Get(urlUserInfo); payState.RequestState = "1"; payState.ProductJson = jsonUserInfo; payState.RequestData = ""; IWechat iwechat = new WechatService(); WechatMemberModel memberInfo = new WechatMemberModel(); memberInfo.ClientId = m; memberInfo.OpenId = payInfo.openid; List <WechatMemberModel> lstMemberInfo = iwechat.IsExistMember(memberInfo); if (lstMemberInfo.Count == 0) { WechatMemberModel createMemberInfo = JsonHandler.GetObjectFromJson <WechatMemberModel>(jsonUserInfo); createMemberInfo.ClientId = m; iwechat.CreateMember(createMemberInfo); } //if(iwechat.IsExistMember(memberInfo)) //log.Info("test"); return(Content(payState)); }