/// <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> /// 授权页回调 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult OpenOAuthCallback(string id) { var reurl = "http://openapp.vzan.com/test/index"; var appid = "wx9a6ab00a752e10e8"; string auth_code = Request["auth_code"]; int areacode = int.Parse(Request["AreaCode"]?.ToString()); int expires_in = Convert.ToInt32(Request["expires_in"]); var currentmodel = opencomponentconfigBLL.SingleModel.getCurrentModel(); string token = currentmodel.component_access_token; //使用授权码获取小程序授权信息 var queryAuthResult = ComponentApi.QueryAuth(token, appid, auth_code); try { var authorizerInfoResult = ComponentApi.GetAuthorizerInfo(token, appid, queryAuthResult.authorization_info.authorizer_appid); StringBuilder str = new StringBuilder(); foreach (FuncscopeCategoryItem item in queryAuthResult.authorization_info.func_info) { str.Append(item.funcscope_category.id.ToString() + ","); } string func_info = str.ToString(); if (func_info.Length > 0) { func_info = func_info.Substring(0, func_info.Length - 1); } #region 公众号详细信息 OpenAuthorizerConfig openconfig = OpenAuthorizerConfigBLL.SingleModel.GetModel("user_name='" + authorizerInfoResult.authorizer_info.user_name + "'"); if (openconfig == null) { openconfig = new OpenAuthorizerConfig(); } openconfig.alias = authorizerInfoResult.authorizer_info.alias; openconfig.appid = queryAuthResult.authorization_info.authorizer_appid; openconfig.func_info = func_info; openconfig.head_img = authorizerInfoResult.authorizer_info.head_img; openconfig.nick_name = authorizerInfoResult.authorizer_info.nick_name; openconfig.qrcode_url = authorizerInfoResult.authorizer_info.qrcode_url; openconfig.service_type_info = (int)authorizerInfoResult.authorizer_info.service_type_info.id; openconfig.user_name = authorizerInfoResult.authorizer_info.user_name; openconfig.verify_type_info = (int)authorizerInfoResult.authorizer_info.verify_type_info.id; openconfig.state = 1; //openconfig.minisnsid = areacode; if (openconfig.id > 0) { OpenAuthorizerConfigBLL.SingleModel.Update(openconfig); } else { OpenAuthorizerConfigBLL.SingleModel.Add(openconfig); } OpenAuthorizerInfo info = OpenAuthorizerInfoBLL.SingleModel.GetModel(string.Format("user_name='{0}'", authorizerInfoResult.authorizer_info.user_name)); if (info == null) { info = new OpenAuthorizerInfo(); } info.addtime = DateTime.Now; info.authorizer_access_token = queryAuthResult.authorization_info.authorizer_access_token; info.authorizer_appid = authorizerInfoResult.authorization_info.authorizer_appid; info.authorizer_refresh_token = queryAuthResult.authorization_info.authorizer_refresh_token; info.refreshtime = DateTime.Now; info.status = 1; //info.minisnsid = areacode; info.user_name = authorizerInfoResult.authorizer_info.user_name; if (info.id > 0) { OpenAuthorizerInfoBLL.SingleModel.Update(info); } else { OpenAuthorizerInfoBLL.SingleModel.Add(info); } #endregion return(Redirect(reurl)); } catch (ErrorJsonResultException ex) { log4net.LogHelper.WriteError(this.GetType(), ex); return(Content(ex.Message)); } }