Пример #1
0
        public APIResult QuerySubmit(string authorizerAccessToken, ShopWechatOpenAuthorizer item, TemplateInfo tempInfo)
        {
            string text        = string.Format("https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token={0}", authorizerAccessToken);
            var    queryResult = CommonJsonSend.Send <GetAuditStatusResultJson>(null, text, null, CommonJsonSendType.GET, 1000, false, null);

            if (queryResult.errcode != Senparc.Weixin.ReturnCode.请求成功)
            {
                return(Error("查询发布失败," + queryResult.errmsg));
            }
            //如果请求成功,则将请求的结果写入到数据库中

            item.CurrentAuditStatus     = queryResult.status;//审核状态,其中0为审核成功,1为审核失败,2为审核中
            item.CurrentAuditFailReason = queryResult.reason;
            db.SaveChanges();
            if (queryResult.status == 0) //审核通过,马上发布
            {
                if (!item.IsRelease)
                {
                    var releaseResult = ReleaseVersion(authorizerAccessToken, item, tempInfo);
                    return(releaseResult);
                }
                else
                {
                    item.CurrentTemplateUserVersion = item.ReleaseTemplateUserVersion;
                    db.SaveChanges();
                }
            }

            return(Success());
        }
Пример #2
0
        /// <summary>
        /// 发布已通过版本
        /// </summary>
        /// <param name="authorizerAccessToken"></param>
        /// <param name="shopId"></param>
        /// <param name="logDbContext"></param>
        public APIResult ReleaseVersion(string authorizerAccessToken, ShopWechatOpenAuthorizer item, TemplateInfo tempInfo)
        {
            var releaseResult = CodeApi.Release(authorizerAccessToken);

            //如果发布成功,则将请求的结果写入到数据库中
            if (releaseResult.errcode != Senparc.Weixin.ReturnCode.请求成功)
            {
                return(Error("发布失败," + releaseResult.errmsg));
            }

            item.IsRelease = true;
            item.CurrentTemplateUserVersion = item.ReleaseTemplateUserVersion;
            item.CurrentTemplateId          = tempInfo.template_id;
            item.CurrentTemplateUserDesc    = tempInfo.user_desc;
            db.SaveChanges();
            //这里尝试添加二唯码规则
            if (hostingEnvironment != null)
            {
                var qrCodeResult = CodeApiExt.QRCodeJumpAddPublish(item.ShopId, authorizerAccessToken, hostingEnvironment);
                if (qrCodeResult.errcode != ReturnCode.请求成功)
                {
                    return(Error("添加二维码规则失败 ," + qrCodeResult.errmsg));
                }
            }
            return(Success());
        }
Пример #3
0
        /// <summary>
        /// 提交审核
        /// </summary>
        /// <param name="authorizerAccessToken"></param>
        /// <param name="item"></param>
        /// <param name="tempInfo"></param>
        public APIResult SubmitVersion(string authorizerAccessToken, ShopWechatOpenAuthorizer item, TemplateInfo tempInfo)
        {
            //先上传代码
            string extJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(new { ext = new { shopFlag = item.Shop.Flag } });
            var    commitResult  = CodeApi.Commit(authorizerAccessToken, tempInfo.template_id, extJsonString, tempInfo.user_version, tempInfo.user_desc);

            //如果请求成功,则将请求的参数写入到数据库进行保存
            if (commitResult.errcode != Senparc.Weixin.ReturnCode.请求成功)
            {
                return(Error("上传代码失败," + commitResult.errmsg));
            }

            //提交审核
            List <SubmitAuditPageInfo> list = new List <SubmitAuditPageInfo>();
            CategroyInfo category           = AuthorizerHelper.GetCategory(authorizerAccessToken);

            list.Add(new SubmitAuditPageInfo()
            {
                first_id     = category.first_id,
                second_id    = category.second_id,
                first_class  = category.first_class,
                second_class = category.second_class,
                third_class  = category.third_class,
                third_id     = category.third_id,
                title        = "点餐",
                tag          = category.first_class,
                address      = "pages/home/home"
            });
            try
            {
                var submitAuditResult = CodeApi.SubmitAudit(authorizerAccessToken, list);

                if (submitAuditResult.errcode != ReturnCode.请求成功)
                {
                    return(Error("提交审核失败," + submitAuditResult.errmsg));
                }
                item.CurrentTemplateExtJson     = extJsonString;
                item.CurrentAuditId             = int.Parse(submitAuditResult.auditid);
                item.CurrentAuditStatus         = 2; //审核状态,其中0为审核成功,1为审核失败,2为审核中
                item.ReleaseTemplateUserVersion = tempInfo.user_version;
                item.IsRelease = false;              //将发布状态设置为未发布
                db.SaveChanges();

                if (item.CurrentAuditStatus == 0) //审核通过则马上发布
                {
                    ReleaseVersion(authorizerAccessToken, item, tempInfo);
                }
            }
            catch (Exception ex)
            {
                return(Error("提交审核失败," + ex.Message));
            }

            return(Success());
        }
Пример #4
0
        public APIResult AutoUpgrade(ShopWechatOpenAuthorizer item, TemplateInfo tempInfo)
        {
            var authorizerAccessToken = AuthorizerHelper.GetAuthorizerAccessToken(item.WechatOpenAuthorizer.AuthorizerAppId);

            //检查是否已创建开放平台和绑定,此功能目的是为了登录时获取到unionid
            var bindResult = AuthorizerHelper.CreateAndBindOpen(item.WechatOpenAuthorizer.AuthorizerAppId);

            //当前店铺不是最新版 提交审核
            if (item.ReleaseTemplateUserVersion != tempInfo.user_version)
            {
                return(SubmitVersion(authorizerAccessToken, item, tempInfo));
            }
            else     //已提交审核则查询审核状态
            {
                if (item.CurrentTemplateUserVersion != item.ReleaseTemplateUserVersion)
                {
                    return(QuerySubmit(authorizerAccessToken, item, tempInfo));
                }
            }
            return(Success());
        }
Пример #5
0
        public ActionResult OAuthCallback(string auth_code, int expires_in, int shopId)
        {
            logger.LogInformation($"================================调试开始====================================");
            try
            {
                #region 查询授权信息
                var componentAppId    = wechatOpenOptions.AppId;
                var authorizationCode = auth_code;
                var accessToken       = ZRui.Web.BLL.AuthorizerHelper.GetComponentAccessToken();
                var queryAuthResult   = ComponentApi.QueryAuth(accessToken, componentAppId, authorizationCode);
                logger.LogInformation($"授权返回信息queryAuthResult:{queryAuthResult}");
                var authorizerAppid   = queryAuthResult.authorization_info.authorizer_appid;
                var authorizationInfo = queryAuthResult.authorization_info;
                #endregion

                WechatOpenAuthorizer authorizer = null;
                var authorizers = db.Query <WechatOpenAuthorizer>().
                                  Where(p => p.AuthorizerAppId == authorizationInfo.authorizer_appid);
                if (authorizers.Count() > 0)
                {
                    authorizer = authorizers.FirstOrDefault(p => !p.IsDel);
                    if (authorizer != null)
                    {
                        return(Content("当前店铺绑定的小程序已经存在"));
                    }
                    else
                    {
                        authorizer       = authorizers.OrderByDescending(p => p.Id).FirstOrDefault();
                        authorizer.IsDel = false;
                    }
                }
                else
                {
                    authorizer = new WechatOpenAuthorizer();
                    db.Add(authorizer);
                }


                authorizer.AddIp                  = GetIp();
                authorizer.AddTime                = DateTime.Now;
                authorizer.AddUser                = GetUsername();
                authorizer.AuthorizerAppId        = queryAuthResult.authorization_info.authorizer_appid;
                authorizer.AuthorizerAccessToken  = queryAuthResult.authorization_info.authorizer_access_token;
                authorizer.AuthorizerRefreshToken = queryAuthResult.authorization_info.authorizer_refresh_token;
                authorizer.ExpiresIn              = queryAuthResult.authorization_info.expires_in;
                authorizer.ExpiresTime            = DateTime.Now.AddSeconds(queryAuthResult.authorization_info.expires_in);


                GetAuthorizerInfoResult authorizerInfoResult = ComponentApi.GetAuthorizerInfo(accessToken, componentAppId, authorizerAppid, 0x2710);

                authorizer.AuthorizerNickname = authorizerInfoResult.authorizer_info.nick_name;
                //这里的Username是原始Id
                authorizer.AuthorizerUsername = authorizerInfoResult.authorizer_info.user_name;


                db.SaveChanges();



                ShopWechatOpenAuthorizer shopAuth = null;
                var shopAuths = db.Query <ShopWechatOpenAuthorizer>()
                                .Where(m => m.ShopId == shopId);
                if (shopAuths.Count() > 0)
                {
                    shopAuth = shopAuths.FirstOrDefault(p => !p.IsDel);
                    if (shopAuth == null)
                    {
                        shopAuth = shopAuths.OrderByDescending(p => p.Id).FirstOrDefault();
                    }
                    shopAuth.IsDel = false;
                }
                else
                {
                    shopAuth = new ShopWechatOpenAuthorizer()
                    {
                        ShopId = shopId,
                    };
                    db.Add(shopAuth);
                }
                shopAuth.WechatOpenAuthorizerId = authorizer.Id;
                db.SaveChanges();


                ///初始化
                //复制一份授权信息到auth数据库
                ZRui.Web.BLL.AuthorizerHelper.InsertOrUpdateAuthorizer(authorizer);
                //设置请求域以及添加跳转二维码
                var initShop = CodeApiExt.QRCodeJumpAddPublish(shopId, authorizer.AuthorizerAccessToken, hostingEnvironment);
                //创建开放平台--为了获取授权信息时含有unionid
                AuthorizerHelper.CreateAndBindOpen(authorizer.AuthorizerAppId);


                ViewData["QueryAuthorizationInfo"]  = queryAuthResult.authorization_info;
                ViewData["GetAuthorizerInfoResult"] = authorizerInfoResult.authorizer_info;
                return(View());
            }
            catch (ErrorJsonResultException ex)
            {
                return(Content(ex.Message));
            }
        }
Пример #6
0
 /// <summary>
 /// 发布已通过版本
 /// </summary>
 /// <param name="authorizerAccessToken"></param>
 /// <param name="shopId"></param>
 /// <param name="logDbContext"></param>
 public APIResult ReleaseVersion(string authorizerAccessToken, ShopWechatOpenAuthorizer item, TemplateInfo tempInfo)
 {
     return(autotask.ReleaseVersion(authorizerAccessToken, item, tempInfo));
 }
Пример #7
0
 public APIResult QuerySubmit(string authorizerAccessToken, ShopWechatOpenAuthorizer item, TemplateInfo tempInfo)
 {
     return(autotask.QuerySubmit(authorizerAccessToken, item, tempInfo));
 }
Пример #8
0
 public APIResult AutoUpgrade(ShopWechatOpenAuthorizer item, TemplateInfo tempInfo)
 {
     return(autotask.AutoUpgrade(item, tempInfo));
 }