public SeccessModel GetApiJsonStringnoappsr(string js_code, string appid) { JsonSerializerSettings setting = new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; SeccessModel resultmodel = new SeccessModel(); UserXcxTemplate umodel = UserXcxTemplateBLL.SingleModel.GetModelByAppId(appid); if (umodel != null) { XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(appid); if (xcxrelation != null) { XcxApiBLL.SingleModel._openType = xcxrelation.ThirdOpenType; } string url = XcxApiBLL.SingleModel.GetSessionKey(appid.Trim(), js_code); string result = HttpHelper.GetData(url); if (!string.IsNullOrEmpty(result)) { XcxApiRequestJson <object> data = JsonConvert.DeserializeObject <XcxApiRequestJson <object> >(result, setting); if (data != null && data.obj != null) { if (!string.IsNullOrEmpty(data.obj.session_key)) { resultmodel.session_key = data.obj.session_key; resultmodel.openid = data.obj.openid; resultmodel.isok = 1; resultmodel.msg = "OK"; } else { resultmodel.isok = -1; resultmodel.msg = data.msg; } } else { resultmodel.isok = -1; resultmodel.msg = "获取秘钥null" + result; } } else { resultmodel.isok = -1; resultmodel.msg = result; } } else { resultmodel.isok = -1; resultmodel.msg = "没有上传记录"; } return(resultmodel); }
/// <summary> /// 处理小程序代码审核回调 /// </summary> public static void CommandXCXPublish(string returntype, XDocument postDataDocument) { string username = postDataDocument.Root.Element("ToUserName").Value; string reason = string.Empty; //小程序代码审核成功回调 OpenAuthorizerInfo amodel = OpenAuthorizerInfoBLL.SingleModel.getCurrentModel(username); if (amodel == null) { log4net.LogHelper.WriteInfo(typeof(WXRequestCommandBLL), "【" + returntype + "】" + username + "微信回调:找不到授权记录"); return; } //小程序上传代码记录 UserXcxTemplate userxcxtemplate = UserXcxTemplateBLL.SingleModel.GetModelByUserName(username); if (userxcxtemplate == null) { log4net.LogHelper.WriteInfo(typeof(WXRequestCommandBLL), "【" + returntype + "】" + username + "微信回调:找不到小程序上传代码记录"); return; } //代码审核通过 if (returntype == "weapp_audit_success") { //发布审核通过的小程序代码 var cresult = WxRequest.Release(amodel.authorizer_access_token); userxcxtemplate.PreAuditId = userxcxtemplate.Auditid; //更改上传记录信息 userxcxtemplate.State = cresult.errcode == 0 ? 3 : 4; userxcxtemplate.UpdateTime = DateTime.Now; userxcxtemplate.Reason = cresult.errcode == 0 ? "发布成功" : "发布失败" + cresult.errcode.ToString(); } else { //更改上传记录信息 userxcxtemplate.State = 1; userxcxtemplate.UpdateTime = DateTime.Now; userxcxtemplate.Reason = "审核不通过," + postDataDocument.Root.Element("Reason").Value; } UserXcxTemplateBLL.SingleModel.Update(userxcxtemplate, "Reason,UpdateTime,State,PreAuditId"); }
/// <summary> /// 小程序登陆通过个人获取sessionkey /// </summary> /// <param name="js_code"></param> /// <param name="appid"></param> /// <param name="msg"></param> /// <returns></returns> public UserSession GetAppSessionInfoByAppsr(string js_code, string appid, ref string msg) { UserSession session = new UserSession(); UserXcxTemplate userXcxModel = UserXcxTemplateBLL.SingleModel.GetModelByAppId(appid); if (userXcxModel == null || string.IsNullOrEmpty(userXcxModel.Appsr)) { msg = "密钥不能为空"; return(session); } string url = Jscode2sessionUrl(appid, js_code, userXcxModel.Appsr); string resultJson = CommonCore.HttpGet(url); if (string.IsNullOrEmpty(resultJson)) { msg = "获取小程序sessionkey返回值为空"; return(session); } session = JsonConvert.DeserializeObject <UserSession>(resultJson); if (session.errcode == "40029") { msg = "不可用的code,原因是开发工具添加项目时填写的appid跟app.js里的appid不一致"; return(session); } if (session.errcode == "40125") { msg = "不可用的秘钥,原因是手动发布的小程序后台没有保存秘钥,或者秘钥被重置过不可"; return(session); } if (string.IsNullOrEmpty(session.session_key)) { msg = "登陆失败,获取sessionkey失败"; } return(session); }
/// <summary> /// 获取小程序名称 /// </summary> /// <param name="aid"></param> /// <param name="model"></param> /// <returns></returns> public string GetAppName(int aid, XcxAppAccountRelation model = null, UserXcxTemplate userxcxTmpelate = null, OpenAuthorizerConfig openModel = null) { if (model == null) { if (aid <= 0) { return(""); } model = base.GetModel(aid); } if (model == null) { return(""); } if (model.AuthoAppType == 0) { if (userxcxTmpelate == null) { userxcxTmpelate = UserXcxTemplateBLL.SingleModel.GetModelByAppId(model.AppId); } return(userxcxTmpelate?.Name); } else if (model.AuthoAppType == 1) { if (openModel == null) { openModel = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(model.AppId); } return(openModel?.nick_name); } return(""); }
/// <summary> /// 获取首页轮播图以及推荐商家 /// </summary> /// <returns></returns> public ActionResult GetConfig() { returnObj = new Return_Msg_APP(); returnObj.code = "200"; string appId = Context.GetRequest("appId", string.Empty); if (string.IsNullOrEmpty(appId)) { returnObj.Msg = "参数错误"; return(Json(returnObj)); } int pageIndexAdImg = Context.GetRequestInt("pageIndexAdImg", 1); int pageSizeAdImg = Context.GetRequestInt("pageSizeAdImg", 10); int pageIndexTjStore = Context.GetRequestInt("pageIndexTjStore", 1); int pageSizeTjStore = Context.GetRequestInt("pageSizeTjStore", 20); XcxAppAccountRelation r = _xcxAppAccountRelationBLL.GetModelByAppid(appId); if (r == null) { returnObj.Msg = "小程序未授权"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); } string appname = ""; OpenAuthorizerConfig openonfigmodel = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(r.AppId); if (openonfigmodel != null) { appname = openonfigmodel.nick_name; } else { UserXcxTemplate userXcxModel = UserXcxTemplateBLL.SingleModel.GetModelByAppId(r.AppId); appname = userXcxModel?.Name; } int adImgCount, tjStoreCount = 0; List <PlatConfig> listADImg = PlatConfigBLL.SingleModel.getListByaid(r.Id, out adImgCount, 0, pageSizeAdImg, pageIndexAdImg); List <PlatConfig> listTjStore = PlatConfigBLL.SingleModel.getListByaid(r.Id, out tjStoreCount, 1, pageSizeTjStore, pageIndexTjStore); string lngStr = Context.GetRequest("lng", string.Empty); string latStr = Context.GetRequest("lat", string.Empty); double lng = 0.00; double lat = 0.00; string curLocation = "未知城市"; int curCityCode = 0; if (!double.TryParse(lngStr, out lng) || !double.TryParse(latStr, out lat)) { string IP = WebHelper.GetIP(); IPToPoint iPToPoint = CommondHelper.GetLoctionByIP(IP); if (iPToPoint != null) { lat = iPToPoint.result.location.lat; lng = iPToPoint.result.location.lng; lngStr = lng.ToString(); latStr = lat.ToString(); //log4net.LogHelper.WriteInfo(this.GetType(), $"IP={IP};{lat},{lng}"); } } AddressApi addressinfo = AddressHelper.GetAddressByApi(lngStr, latStr); // log4net.LogHelper.WriteInfo(this.GetType(), Newtonsoft.Json.JsonConvert.SerializeObject(addressinfo)); if (addressinfo != null && addressinfo.result != null && addressinfo.result.address_component != null) { curLocation = addressinfo.result.address_component.city; curCityCode = C_AreaBLL.SingleModel.GetCodeByName(curLocation); } listTjStore.ForEach(x => { x.ObjName = x.ObjName.Length > 6 ? (x.ObjName.Substring(0, 5) + "...") : x.ObjName; }); PlatConfig platConfigRemark = PlatConfigBLL.SingleModel.GetPlatConfig(r.Id, 3); var remarkObj = new { haveRemark = false, remark = string.Empty, remarkOpenFrm = false }; if (platConfigRemark != null && !string.IsNullOrEmpty(platConfigRemark.ADImg)) { remarkObj = new { haveRemark = true, remark = platConfigRemark.ADImg, remarkOpenFrm = platConfigRemark.ObjId == 0 }; } PlatConfig platOther = PlatConfigBLL.SingleModel.GetPlatConfig(r.Id, 5);//获取平台其它设置 if (platOther == null) { platOther = new PlatConfig() { Aid = r.Id, AddTime = DateTime.Now, ConfigType = 5 }; } PlatOtherConfig platOtherConfig = new PlatOtherConfig(); platOtherConfig.VirtualPV = platOther.ADImgType; platOtherConfig.VirtualPlatMsgCount = platOther.ObjId; platOtherConfig.PlatMsgCount = PlatMsgBLL.SingleModel.GetCountByAId(r.Id); platOtherConfig.PV = PlatStatisticalFlowBLL.SingleModel.GetPVCount(r.Id); int totalPV = platOtherConfig.VirtualPV + platOtherConfig.PV; int totalMsgCout = platOtherConfig.PlatMsgCount + platOtherConfig.VirtualPlatMsgCount; PlatConfig platOfficialAccount = PlatConfigBLL.SingleModel.GetPlatConfig(r.Id, 6);//获取关注公众号设置 if (platOfficialAccount == null) { platOfficialAccount = new PlatConfig() { Aid = r.Id, AddTime = DateTime.Now, ConfigType = 6 }; } returnObj.dataObj = new { appname = appname, ADImgs = new { totalCount = adImgCount, list = listADImg }, TjStores = new { totalCount = tjStoreCount, list = listTjStore }, Location = new { curLocation = curLocation, curCityCode = curCityCode }, platConfigRemark = remarkObj, platOtherConfig = new { TotalPV = totalPV > 100000?Convert.ToInt32(totalPV * 0.0001).ToString() + "万+": totalPV.ToString(), TotalMsgCount = totalMsgCout > 100000? Convert.ToInt32(totalMsgCout * 0.0001).ToString() + "万+": totalMsgCout.ToString() }, platOfficialAccount = platOfficialAccount }; returnObj.isok = true; returnObj.Msg = "获取成功"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 不通过第三方授权平台获取小程序token /// </summary> /// <param name="appId"></param> /// <returns></returns> public GongZhongToken GetGongZhongToken(string appId) { string key = string.Format(_redis_MiniappGongZhongToken, appId); GongZhongToken model = RedisUtil.Get <GongZhongToken>(key); if (model == null) { model = new GongZhongToken(); } if (string.IsNullOrEmpty(appId)) { model.errmsg = "公众号token:appid不能为空"; model.errcode = "-1"; return(model); } UserXcxTemplate userxcxModel = UserXcxTemplateBLL.SingleModel.GetModelByAppId(appId); if (userxcxModel == null) { model.errmsg = "公众号token:上传记录为空"; model.errcode = "-1"; return(model); } if (string.IsNullOrEmpty(userxcxModel.Appsr)) { model.errmsg = "公众号token:小程序密码为空"; model.errcode = "-1"; return(model); } //token为空或者超过100分钟,重新获取token if (string.IsNullOrEmpty(model.access_token) || model.UpdateTime < DateTime.Now.AddMinutes(100)) { lock (_lockObj) { model = RedisUtil.Get <GongZhongToken>(key); if (model == null) { model = new GongZhongToken(); } if (string.IsNullOrEmpty(model.access_token) || model.UpdateTime < DateTime.Now.AddMinutes(100)) { string url = GetGongZhonTokenUrl(userxcxModel.AppId, userxcxModel.Appsr); string resultStr = HttpHelper.GetData(url); if (string.IsNullOrEmpty(resultStr)) { model.errmsg = "公众号token:获取公众号token失败"; model.errcode = "-1"; return(model); } GongZhongToken resultData = JsonConvert.DeserializeObject <GongZhongToken>(resultStr); if (resultData == null) { model.errmsg = "公众号token:获取token为null"; model.errcode = "-1"; return(model); } if (resultData.errcode == "0") { resultData.AppId = userxcxModel.AppId; resultData.AddTime = model.AddTime; resultData.UpdateTime = DateTime.Now; RedisUtil.Set <GongZhongToken>(key, resultData); model = resultData; } else { log4net.LogHelper.WriteInfo(this.GetType(), "公众号token:" + JsonConvert.SerializeObject(resultData)); model.errmsg = "公众号token:获取token失败"; model.errcode = "-1"; return(model); } } } } return(model); }
public ActionResult GetUserTemplatesList() { int pageindex = Context.GetRequestInt("pageindex", 1); int pagesize = Context.GetRequestInt("pagesize", 20); try { Account account = AccountBLL.SingleModel.GetModel(dzuserId); List <XcxAppAccountRelation> miniapplist = new List <XcxAppAccountRelation>(); List <object> mytemplatelist = new List <object>(); if (account != null) { bool ismodel = _customerLoginId.Contains(account.LoginId); #region 小程序 //判断是否是代理登陆 if (agentaccount != null && agentinfo != null && agentinfo.id > 0 && dzuserId != agentuserId) { miniapplist = XcxAppAccountRelationBLL.SingleModel.GetListByaccountIdandAgentId(account.Id.ToString(), agentinfo.id, 0, pagesize, pageindex); } else { miniapplist = XcxAppAccountRelationBLL.SingleModel.GetListByaccountIdandAgentId(account.Id.ToString(), 0, 0, pagesize, pageindex); } if (miniapplist != null && miniapplist.Count > 0) { List <CustomModelRelation> customModelList = new List <CustomModelRelation>(); if (ismodel) { string aids = string.Join(",", miniapplist.Select(s => s.Id)); customModelList = CustomModelRelationBLL.SingleModel.GetListByAIds(aids); } string ids = string.Join(",", miniapplist.Select(s => s.TId).Distinct()); List <XcxTemplate> xcxtemplatelist = XcxTemplateBLL.SingleModel.GetList("id in (" + ids + ")"); if (xcxtemplatelist != null && xcxtemplatelist.Count > 0) { string appIds = $"'{string.Join("','", miniapplist.Where(w=>!string.IsNullOrEmpty(w.AppId))?.Select(s=>s.AppId))}'"; List <UserXcxTemplate> userXcxTemplateList = UserXcxTemplateBLL.SingleModel.GetListByAppIds(appIds); foreach (XcxAppAccountRelation item in miniapplist) { List <OpenAuthorizerConfig> authomodellist = OpenAuthorizerConfigBLL.SingleModel.GetListByaccoundidAndRid(item.AccountId.ToString(), item.Id); XcxTemplate xcxtempmodel = xcxtemplatelist.Where(w => w.Id == item.TId).FirstOrDefault(); if (item.AuthoAppType == 1) { if (!string.IsNullOrEmpty(item.AppId)) { OpenAuthorizerConfig authomodel = authomodellist != null && authomodellist.Count > 0 ? authomodellist[0] : null; if (authomodel != null) { item.XcxName = authomodel.nick_name; UserXcxTemplate uploadmodel = userXcxTemplateList?.FirstOrDefault(f => f.AppId == item.AppId); if (uploadmodel != null) { if (uploadmodel.AddTime.ToString("yyyy-MM-dd") == "0001-01-01") { uploadmodel.State = (int)XcxTypeEnum.未发布; UserXcxTemplateBLL.SingleModel.Update(uploadmodel, "state"); } item.UploadState = uploadmodel.State; item.UploadStateName = Enum.GetName(typeof(XcxTypeEnum), uploadmodel.State); } else { item.UploadState = (int)XcxTypeEnum.未发布; item.UploadStateName = XcxTypeEnum.未发布.ToString(); } } } else { item.XcxName = "未绑定"; item.UploadState = (int)XcxTypeEnum.未发布; item.UploadStateName = XcxTypeEnum.未发布.ToString(); } } else { UserXcxTemplate uploadmodel = userXcxTemplateList?.FirstOrDefault(f => f.AppId == item.AppId); item.XcxName = uploadmodel?.Name; } if (item.outtime <= DateTime.Now) { item.TimeLength = 0; } else { TimeSpan sp = item.outtime.Subtract(DateTime.Now); item.TimeLength = sp.Days <= 0?1:sp.Days; } if (xcxtempmodel != null) { string bangdinurl = "/Config/MiniAppConfig?appId=" + item.Id + "&id=" + item.Id + "&type=" + xcxtempmodel.Type; string TName = xcxtempmodel.TName.Replace("专业版", "专业"); if (xcxtempmodel.Type == 22) { TName += AgentdepositLogBLL.SingleModel.GetVerName(item.VersionId); } string modelname = ""; if (ismodel) { modelname = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.Name; modelname = string.IsNullOrEmpty(modelname) ? TName : modelname; } mytemplatelist.Add(new { Id = item.Id, Title = TName, Url = "/" + item.Url + "?Id=" + item.Id + "&appId=" + item.Id + "&versionId=" + item.VersionId,//跳转管理路径 item.TimeLength, outtime = item.outtime.ToString("yyyy-MM-dd"), XcxName = item.XcxName, UploadState = item.UploadState, UploadStateName = item.UploadStateName, item.State, item.AppId, xcxtempmodel.Type, bangdinurl = bangdinurl, //绑定路径 yulang = $"/config/GettestQrcode?Id={item.Id}&tid={item.TId}&needpay=0", //预览路径 iosimg = "", logoimg = xcxtempmodel.TImgurl, //小图标 item.IsExperience, ismodel, modelstate = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.State, modelname, modeldesc = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.Desc, modelimgurl = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.ImgUrl, }); } } } } return(Json(new { isok = 1, msg = "成功", obj = mytemplatelist, accountid = dzuserId }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { isok = -1, msg = "找不到用户信息", obj = new List <object>() }, JsonRequestBehavior.AllowGet)); } #endregion } catch (Exception ex) { log4net.LogHelper.WriteError(this.GetType(), ex); } return(Json(new { isok = -1, msg = "获取用户已开通模板数据出错", obj = new List <object>() }, JsonRequestBehavior.AllowGet)); }
public JsonResult App(Account account) { List <XcxAppAccountRelation> apps = XcxAppAccountRelationBLL.SingleModel.GetListByTemplateType(account.Id.ToString(), TmpType.智慧餐厅); if (apps == null || apps.Count == 0) { return(ApiModel(message: "没有开通智慧餐厅")); } List <XcxTemplate> appTemplates = XcxTemplateBLL.SingleModel.GetListByIds(string.Join(",", apps.Select(s => s.TId).Distinct())); List <OpenAuthorizerConfig> appConfigs = OpenAuthorizerConfigBLL.SingleModel.GetListByaccoundidAndRid(account.Id.ToString(), string.Join(",", apps.Select(item => item.Id))); string appIds = $"'{string.Join("','", apps.FindAll(item => !string.IsNullOrEmpty(item.AppId)).Select(s => s.AppId))}'"; List <UserXcxTemplate> appPublish = UserXcxTemplateBLL.SingleModel.GetListByAppIds(appIds); object formatDTO = apps.Select(app => { XcxTemplate template = appTemplates.Where(thisItem => thisItem.Id == app.TId).FirstOrDefault(); if (app.AuthoAppType == 1) { OpenAuthorizerConfig config = appConfigs.FirstOrDefault(thisItem => thisItem.RId == app.Id); app.XcxName = config?.nick_name; app.UploadStateName = XcxTypeEnum.未发布.ToString(); if (config != null && !string.IsNullOrWhiteSpace(app.AppId)) { UserXcxTemplate publish = appPublish?.FirstOrDefault(item => item.AppId == app.AppId); if (publish != null) { if (publish.AddTime.ToString("yyyy-MM-dd") == "0001-01-01") { publish.State = (int)XcxTypeEnum.未发布; UserXcxTemplateBLL.SingleModel.Update(publish, "state"); } app.UploadStateName = Enum.GetName(typeof(XcxTypeEnum), publish.State); } } } else { app.XcxName = appPublish?.FirstOrDefault(f => f.AppId == app.AppId)?.Name; app.UploadStateName = "手动发布"; } if (string.IsNullOrWhiteSpace(app.XcxName)) { app.XcxName = "未绑定公众号小程序"; } string expireDay = string.Empty; if (app.outtime <= DateTime.Now) { expireDay = "0天"; } else { expireDay = Convert.ToInt32(Math.Round(app.outtime.Subtract(DateTime.Now).TotalDays)).ToString() + "天"; } return(new { app.Id, Template = template.TName, AppTitle = app.XcxName, Icon = template.TImgurl, ExpireDay = expireDay, StoreCount = app.SCount, PublishState = app.UploadStateName, }); }); return(ApiModel(isok: true, message: "获取成功", data: formatDTO)); }