From bfdbbf1eaf8a06cdc49910a8971157dd306ea9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?old=E6=98=93?= <156663459@qq.com> Date: Fri, 29 Mar 2024 14:13:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B6=88=E6=81=AF=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Front/CustomerController.cs | 4 +- New_College.Common/Helper/WeixinHelper.cs | 37 +++++++++++++++++++ .../V_CustomerInfoServices.cs | 28 ++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/New_College.Api/Controllers/Front/CustomerController.cs b/New_College.Api/Controllers/Front/CustomerController.cs index b0df553..a2993c8 100644 --- a/New_College.Api/Controllers/Front/CustomerController.cs +++ b/New_College.Api/Controllers/Front/CustomerController.cs @@ -9,12 +9,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using MySqlX.XDevAPI.Common; using New_College.AuthHelper.OverWrite; +using New_College.Common; using New_College.IServices; using New_College.Model; using New_College.Model.Models; using New_College.Model.Request; using New_College.Model.ViewModels; -using Org.BouncyCastle.Asn1.Ocsp; namespace New_College.Api.Controllers.Front { @@ -273,6 +273,7 @@ namespace New_College.Api.Controllers.Front var count = (await _fansDistributionServices.Query(e => e.SaleId == saleId)).Count();//判断邀请人数是否满足三个人 if (count >= 3) { + await _services.UpdateIsVip(saleId); } return true; @@ -281,6 +282,7 @@ namespace New_College.Api.Controllers.Front return false; } + /// /// 同步合并数据 /// diff --git a/New_College.Common/Helper/WeixinHelper.cs b/New_College.Common/Helper/WeixinHelper.cs index 86586dc..e031ed3 100644 --- a/New_College.Common/Helper/WeixinHelper.cs +++ b/New_College.Common/Helper/WeixinHelper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Security.Cryptography; using System.Text; +using System.Threading.Tasks; using Newtonsoft.Json; using NPOI.SS.Formula.Functions; @@ -76,6 +77,42 @@ namespace New_College.Common } } + + /// + ///消息订阅 + /// + /// + /// + /// + /// + /// + public static T SendSubscribeMessageAsync(string accessToken, string openID, Dictionary data) + { + // 构造请求数据 + var sendMessageRequest = new + { + access_token = accessToken, + page = "pages/index/index", + data = data, + template_id = "ZqRgty6dYqHXEGzUYAGSWcwOzNLNo1kWxMK-PO1dEBc", + touser = openID, + lang = "zh_CN", + miniprogram_state = "formal" + }; + // 发送请求 + var requestUrl = $"https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={accessToken}"; + var jsonContent = JsonConvert.SerializeObject(sendMessageRequest); + using (var httpClient = new HttpClient()) + { + var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json"); + //var response = httpClient.PostAsync(requestUrl, httpContent); + var responseStr = httpClient.PostAsync(requestUrl, httpContent).Result.Content.ReadAsStringAsync().Result; + var obj = JsonConvert.DeserializeObject(responseStr); + return obj; + } + } + + public static T WxaBusinessGetUserPhoneNumber(string access_token, string code) where T : new() { var authinfo = new T(); diff --git a/New_College.Services/V_CustomerInfoServices.cs b/New_College.Services/V_CustomerInfoServices.cs index 75eee6b..c7f41cd 100644 --- a/New_College.Services/V_CustomerInfoServices.cs +++ b/New_College.Services/V_CustomerInfoServices.cs @@ -40,12 +40,40 @@ namespace New_College.Services } + + + /// + /// vip任务订阅 + /// + /// + private void MinProVipSubscribe(string openid) + { + try + { + var data = new Dictionary(); + data.Add("thing6.DATA", "邀请注册"); + data.Add("thing11.DATA", ""); + var access_token = WeixinHelper.GetAccessToken(WeixinConfig.Appid, WeixinConfig.Secret); + var subscribe = WeixinHelper.SendSubscribeMessageAsync(access_token.access_token, openid, data); + } + catch (Exception ex) + { + + } + } + /// /// 根据要求更新vip状态 /// /// public async Task UpdateIsVip(int saleId) { + var single = await this._dal.QueryById(saleId); + if (single == null) + { + MinProVipSubscribe(single.OpenId); + } + return await this._dal.Update(string.Format("update V_CustomerInfo set IsVIP=1 where Id={0}", saleId)); } ///