Exemple #1
0
        /// <summary>
        /// 检测用回复粉丝消息
        /// </summary>
        /// <param name="code">授权码</param>
        /// <param name="openId">用户openid</param>
        private async void ReturnMsg(string code, string openId)
        {
            try
            {
                var util = HttpContext.RequestServices.GetService <IUtilRepository>();

                var token = await WxHelper.GetAuthTokenAsync(code, await util.GetOpenTokenAsync());

                var url     = $"https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={token.authorization_info.authorizer_access_token}";
                var content = new
                {
                    touser  = openId,
                    msgtype = "text",
                    text    = new { content = code + "_from_api" }
                };
                var result = await UtilHelper.RequestAsync(url, content);

                var sendData = JsonConvert.SerializeObject(content);
                Log.Debug(result);
            }
            catch (Exception e)
            {
                Log.Debug("回复消息错误:", e);
            }
        }
Exemple #2
0
        /// <summary>
        /// 授权成功后的回调URL
        /// </summary>
        /// <param name="auth_code"></param>
        /// <param name="expires_in"></param>
        /// <returns></returns>
        public async Task <IActionResult> AuthSuccess([FromQuery] string auth_code, [FromQuery] int expires_in, [FromServices] AppData appData)
        {
            var token = await Service.GetOpenTokenAsync();

            var result = await WxHelper.GetAuthTokenAsync(auth_code, token);

            var openAuth = new OpenAuthInfo
            {
                AppId        = result.authorization_info.authorizer_appid,
                BusinessId   = Business.ID,
                CreateTime   = DateTime.Now,
                RefreshToken = result.authorization_info.authorizer_refresh_token
            };
            await Service.SaveAuthorizerInfoAsync(openAuth);

            return(RedirectToAction("AuthInfo"));
        }