/// <summary> ///1、此例中,fetchToken()直接上传(appId/appKey/appSecurity/appAccount)给小米TokenService,获取Token使用 ///实际上,在生产环境中,fetchToken()应该只上传appAccount+password/cookies给AppProxyService,AppProxyService ///验证鉴权通过后,再上传(appId/appKey/appSecurity/appAccount)给小米TokenService,获取Token后返回给fetchToken() ///2、 appId/appKey/appSecurity绝对不能如此用例一般存放于APP本地 /// </summary> /// <returns>tokenStr</returns> public String FetchToken() { logger.DebugFormat("FetchToken:{0}", appAccount); IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("appId", appId); parameters.Add("appKey", appKey); parameters.Add("appSecret", appSecret); parameters.Add("appAccount", appAccount); string output = JsonConvert.SerializeObject(parameters); HttpWebResponse myResponse = HttpWebResponseUtil.CreatePostHttpResponse(httpUrl, output, null, null, Encoding.UTF8, null); string cookieString = myResponse.Headers["Set-Cookie"]; StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string content = reader.ReadToEnd(); JObject jo = (JObject)JsonConvert.DeserializeObject(content); string code = jo.GetValue("code").ToString(); if (code != "200") { logger.DebugFormat("get token error:{0}", content); return(null); } logger.DebugFormat("get token sucesss:{0}", content); reader.Close(); myResponse.Close(); return(content); }
/// <summary> /// 测试创建一个群 /// </summary> /// <param name="httpUrl">创建群url</param> /// <param name="appAccount">群主id</param> /// <param name="appAccounts">群成员ids,逗号分隔</param> /// <returns></returns> public long CreateNormalTopic(string httpUrl, string appAccount, string appAccounts) { Encoding encoding = Encoding.GetEncoding("utf-8"); IDictionary <string, string> parameters = new Dictionary <string, string>(); IDictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Content-Type", "application/json"); headers.Add("appKey", appKey); headers.Add("appSecret", appSecret); headers.Add("appAccount", appAccount); parameters.Add("topicName", "test"); parameters.Add("accounts", appAccounts); string output = JsonConvert.SerializeObject(parameters); HttpWebResponse myResponse = HttpWebResponseUtil.CreatePostHttpResponse(httpUrl + "/" + appId, output, null, null, encoding, null, headers); string cookieString = myResponse.Headers["Set-Cookie"]; StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string content = reader.ReadToEnd(); JObject jo = (JObject)JsonConvert.DeserializeObject(content); string code = jo.GetValue("code").ToString(); if (code != "200") { logger.DebugFormat("create topic error:{0}", content); return(0); } JObject data = (JObject)jo.GetValue("data"); JObject topicInfo = (JObject)data.GetValue("topicInfo"); return(long.Parse(topicInfo.GetValue("topicId").ToString())); }
/// <summary> /// 获取用户访问小程序数据日趋势 /// </summary> public void GetAnalysisDailyVisitTrend() { try { var rep = ContainerManager.Resolve <IEfRepository>(); LoggerHelper.WriteLogInfo($"[GetAnalysisDailyVisitTrend]:******进入方法!!******"); string getApiTokenUrlStr = getApiTokenUrl + "&appid=" + xappid + "&secret=" + xappsecret; LoggerHelper.WriteLogInfo($"[GetAnalysisDailyVisitTrend]:getApiTokenUrl:" + getApiTokenUrlStr); //获取access_Token string tokenresultStr = HttpWebResponseUtil.CreateGetHttpResponse(getApiTokenUrl, null, null, null); LoggerHelper.WriteLogInfo($"[GetAnalysisDailyVisitTrend]:获取access_Token:" + tokenresultStr); tokenResult model = JsonConvert.DeserializeObject <tokenResult>(tokenresultStr); string beforedate = DateTime.Now.AddDays(-1).ToString("yyyyMMdd"); string postJosn = "{\"begin_date\":\"" + beforedate + "\",\"end_date\":\"" + beforedate + "\"}"; LoggerHelper.WriteLogInfo($"[GetAnalysisDailyVisitTrend]:analysisDailyVisitTrendUrl 参数传递:" + postJosn); //调用小程序接口 string analysisDailyVisitTrendUrlStr = analysisDailyVisitTrendUrl + model.access_token; string dataresult = HttpWebResponseUtil.CreatePostHttpResponse(analysisDailyVisitTrendUrlStr, beforedate, null, null, Encoding.UTF8, null); LoggerHelper.WriteLogInfo($"[GetAnalysisDailyVisitTrend]:analysisDailyVisitTrendUrl 返回值:" + dataresult); Rootobject rootmodel = JsonConvert.DeserializeObject <Rootobject>(dataresult); LoggerHelper.WriteLogInfo($"[GetAnalysisDailyVisitTrend]:访问人数:" + rootmodel.list[0].visit_uv); if (rootmodel != null) { var dailyVisit = rep.FirstOrDefault <AnalysisDailyVisitTrend>(s => s.ref_date == beforedate); if (dailyVisit == null) { var newVisit = new AnalysisDailyVisitTrend(); newVisit.ref_date = beforedate; newVisit.session_cnt = rootmodel.list[0].session_cnt; newVisit.visit_pv = rootmodel.list[0].visit_pv; newVisit.visit_uv = rootmodel.list[0].visit_uv; newVisit.visit_uv_new = rootmodel.list[0].visit_uv_new; newVisit.stay_time_uv = rootmodel.list[0].stay_time_uv; newVisit.stay_time_session = rootmodel.list[0].stay_time_session; newVisit.visit_depth = rootmodel.list[0].visit_depth; newVisit.Id = Guid.NewGuid().ToString(); newVisit.IsDeleted = 0; newVisit.IsEnabled = 0; newVisit.CreateTime = (Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))); rep.Insert(newVisit); rep.SaveChanges(); LoggerHelper.WriteLogInfo($"[RemindMeet]:set HasReminded to 1"); } } //调小程序接口 保存至表单中 //调用时日期都是前一天的 } catch (Exception ex) { LoggerHelper.Error($"--------------------------------------------------------------------------------"); LoggerHelper.Error($"[MSG]:{ex.Message};\n"); LoggerHelper.Error($"[Source]:{ex.Source}\n"); LoggerHelper.Error($"[StackTrace]:{ex.StackTrace}\n"); LoggerHelper.Error($"[StackTrace]:{ex.TargetSite.Name}\n"); LoggerHelper.Error($"[MethodName]:[[SSPC_One_HCP.WebApi.Jobs.wxAnalysisDailyVisitTrend.GetAnalysisDailyVisitTrend]]\n"); LoggerHelper.Error($"--------------------------------------------------------------------------------"); throw ex; } }