1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using Fuel.Core;
- using Fuel.Core.Models;
- using Fuel.Core.Nozzle.Dto;
- using Fuel.Core.Transactions.Dto;
- using Fuel.Core.WechatServer;
- using FuelServer.Core.Entity;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http.Headers;
- using System.Text;
- using System.Threading.Tasks;
- namespace Fuel.Application.Service
- {
- public class SiteService: ISiteService
- {
- public readonly IFreeSql _fsql;
- public SiteService(IFreeSql freeSql)
- {
- _fsql = freeSql;
- }
- public async Task<ServiceResponse> GetSiteInfo()
- {
- Guid Buid = HttpRequestReader.GetCurrentBuId();
- var site = _fsql.Select<businessunitinfo>().Where(_ => _.Buid == Buid ).First();
- var SiteInfo = new {
- site = new {
- Name = site.Name,
- GpsCoordinates = site.GpsCoordinates,
- PaymentMode = site.PaymentMode,
- },
- userInfo = new
- {
- UserName = "",
- UserAvatarUrl = "",
- UserAddress= "",
- UserPhoneNumber = ""
- }
- };
- return ServiceResponse.Ok(SiteInfo);
- }
- public async Task<ServiceResponse> GetAppidSecret(string Code)
- {
- Guid Buid = HttpRequestReader.GetCurrentBuId();
- var site = _fsql.Select<businessunitinfo>().Where(_ => _.Buid == Buid).First();
- if (site == null)
- {
- return ServiceResponse.Error("获取站点小程序appid与Secret失败,BUID:" + Buid);
- }
- WechatUserSessionResponse userSession =
- await WechatLoginCodeToSessionKeyNOpenId(Code, site.Appid,site.Secret);
- var thirdSessionKey = GenerateThirdSessionKey();
- WechatUserSessionRepo.AddUserSession(thirdSessionKey, userSession);
- return ServiceResponse.Ok(thirdSessionKey);
- }
-
-
-
-
-
-
-
- public static async Task<WechatUserSessionResponse> WechatLoginCodeToSessionKeyNOpenId(string jsCode, string AppId, string AppSecret)
- {
- string url = string.Format(WechatConstants.Jscode2sessionUrl,
- AppId, AppSecret, jsCode);
- HttpClient client = new HttpClient();
- client.DefaultRequestHeaders.Accept.Clear();
- client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- HttpResponseMessage response = await client.GetAsync(url);
- if (response.IsSuccessStatusCode)
- {
- var responseContent = await response.Content.ReadAsStringAsync();
- var userSession = JsonConvert.DeserializeObject<WechatUserSessionResponse>(responseContent);
- return userSession;
- }
- else
- {
- return null;
- }
- }
- private string GenerateThirdSessionKey()
- {
- var thirdSessionKey = Guid.NewGuid();
- return thirdSessionKey.ToString();
- }
- }
- }
|