😎1、获取微信用户电话号码后更新微信用户表电话号码属性 2、新增生成带页面参数的小程序二维码接口
This commit is contained in:
parent
8cd9e84b30
commit
7bf7c29429
@ -11,7 +11,8 @@
|
||||
"WxOpenAppId": "",
|
||||
"WxOpenAppSecret": "",
|
||||
"WxToken": "", // 小程序消息推送中的令牌(Token)
|
||||
"WxEncodingAESKey": "" // 小程序消息推送中的消息加解密密钥(EncodingAESKey)
|
||||
"WxEncodingAESKey": "", // 小程序消息推送中的消息加解密密钥(EncodingAESKey)
|
||||
"QRImagePath": "" //小程序生成带参数二维码保存位置(绝对路径 eg: D:\\Web\\wwwroot\\Upload\\QRImage)
|
||||
},
|
||||
// 微信支付
|
||||
"WechatPay": {
|
||||
|
||||
@ -141,4 +141,25 @@ public class VerifySignatureInput
|
||||
/// 随机字符串
|
||||
/// </summary>
|
||||
public string Echostr { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成带参数小程序二维码
|
||||
/// </summary>
|
||||
public class GenerateQRImageInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages/index?id=0001
|
||||
/// </summary>
|
||||
public string PagePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件保存的名称
|
||||
/// </summary>
|
||||
public string ImageName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图片宽度 默认430
|
||||
/// </summary>
|
||||
public int Width { get; set; } = 430;
|
||||
}
|
||||
@ -14,4 +14,11 @@ public class WxOpenIdOutput
|
||||
public class WxPhoneOutput
|
||||
{
|
||||
public string PhoneNumber { get; set; }
|
||||
}
|
||||
|
||||
public class GenerateQRImageOutput
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string ImgPath { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
@ -82,6 +82,23 @@ public class SysWxOpenService : IDynamicApiController, ITransient
|
||||
if (resUserPhoneNumber.ErrorCode != (int)WechatReturnCodeEnum.请求成功)
|
||||
throw Oops.Oh(resUserPhoneNumber.ErrorMessage + " " + resUserPhoneNumber.ErrorCode);
|
||||
|
||||
var wxUser = await _sysOAuthUserRep.GetFirstAsync(p => p.OpenId == input.OpenId);
|
||||
if (wxUser == null)
|
||||
{
|
||||
wxUser = new SysOAuthUser
|
||||
{
|
||||
OpenId = input.OpenId,
|
||||
Mobile = resUserPhoneNumber.PhoneInfo?.PhoneNumber,
|
||||
PlatformType = PlatformTypeEnum.微信小程序
|
||||
};
|
||||
wxUser = await _sysOAuthUserRep.AsInsertable(wxUser).ExecuteReturnEntityAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxUser.Mobile = resUserPhoneNumber.PhoneInfo?.PhoneNumber;
|
||||
await _sysOAuthUserRep.AsUpdateable(wxUser).IgnoreColumns(true).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
return new WxPhoneOutput
|
||||
{
|
||||
PhoneNumber = resUserPhoneNumber.PhoneInfo?.PhoneNumber
|
||||
@ -194,6 +211,68 @@ public class SysWxOpenService : IDynamicApiController, ITransient
|
||||
return resTemplate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成二维码
|
||||
/// </summary>
|
||||
/// <param name="input"> 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages / index ? id = AY000001 </param>
|
||||
/// <returns></returns>
|
||||
[DisplayName("生成小程序二维码")]
|
||||
[ApiDescriptionSettings(Name = "GenerateQRImage")]
|
||||
public async Task<GenerateQRImageOutput> GenerateQRImageAsync(GenerateQRImageInput input)
|
||||
{
|
||||
GenerateQRImageOutput generateQRImageOutInput = new GenerateQRImageOutput();
|
||||
if (input.PagePath.IsNullOrEmpty())
|
||||
{
|
||||
generateQRImageOutInput.Success = false;
|
||||
generateQRImageOutInput.ImgPath = "";
|
||||
generateQRImageOutInput.Message = $"生成失败 页面路径不能为空";
|
||||
return generateQRImageOutInput;
|
||||
}
|
||||
|
||||
if (input.ImageName.IsNullOrEmpty())
|
||||
{
|
||||
input.ImageName = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
}
|
||||
|
||||
var accessToken = await GetCgibinToken();
|
||||
var request = new CgibinWxaappCreateWxaQrcodeRequest
|
||||
{
|
||||
AccessToken = accessToken,
|
||||
Path = input.PagePath,
|
||||
Width = input.Width
|
||||
};
|
||||
var response = await _wechatApiClient.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request);
|
||||
|
||||
if (response.IsSuccessful())
|
||||
{
|
||||
var QRImagePath = App.GetConfig<string>("Wechat:QRImagePath");
|
||||
//判断文件存放路径是否存在
|
||||
if (!Directory.Exists(QRImagePath))
|
||||
{
|
||||
Directory.CreateDirectory(QRImagePath);
|
||||
}
|
||||
// 将二维码图片数据保存为文件
|
||||
var filePath = QRImagePath + $"\\{input.ImageName.ToUpper()}.png";
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
File.WriteAllBytes(filePath, response.GetRawBytes());
|
||||
|
||||
generateQRImageOutInput.Success = true;
|
||||
generateQRImageOutInput.ImgPath = filePath;
|
||||
generateQRImageOutInput.Message = "生成成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理错误情况
|
||||
generateQRImageOutInput.Success = false;
|
||||
generateQRImageOutInput.ImgPath = "";
|
||||
generateQRImageOutInput.Message = $"生成失败 错误代码:{response.ErrorCode} 错误描述:{response.ErrorMessage}";
|
||||
}
|
||||
return generateQRImageOutInput;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Access_token
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user