需求
汽车贷款进单系统,有个电子签功能.电子签功能分app和微信远程签署.
微信远程签署时,会分享小程序二维码.
客户拿到二维码,扫码进入自己的单据进行身份认证,(腾讯核身)电子签~
需求点1:
携带单号以及其他参数,生成小程序码~
实现V1
根据QRCoder生成二维码
/// <summary> /// 生成二维码 /// </summary> /// <param name="id">预授信表id</param> /// <returns>二维码md5值,和失效时间</returns> [Routing(EHttpMethod.HttpGet, "app/code")] public CommonResult<MQCode> CreteCodes(string id) { var result = CreteCode(id, ECaCategory.PreCredit); if (result.WarnResult != null) { return result.WarnResult; } return result.Value; } public CommonResult<MQCode> CreteCode(string id, ECaCategory caCategory) { string qrcodeid = Tools.NewId(); if (String.IsNullOrEmpty(id)) { return new WarnResult("参数为空"); } try { string strCode = "https://open.weixin.qq.com/sns/getexpappinfo?appid=" + _config["WXPrecreditAPPID"] + $"&path=pages/index/index.html?id={id}%26code={qrcodeid}%26time=6#wechat-redirect"; //strCode = HttpUtility.UrlEncode(strCode); QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); #region basestring string baseICO = "这里是base64二维码图标"; #endregion var imgICO = Tools.Base64StringToImage(baseICO); //调用生成二维码
System.Drawing.Bitmap qrCodeImage = qrcode.GetGraphic(5, System.Drawing.Color.Black, System.Drawing.Color.White, imgICO, 15, 6); var path = "UploadFileTemp\\" + _FileHelper.GetFileName(".jpeg"); //调用保存本地
qrCodeImage.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
//调用上传 var result = _FileHelper.UploadFile(path, Guid.NewGuid(), "1200170005"); if (result.WarnResult != null) { throw new Exception(result.WarnResult.Message); } var resModel = _jsonConverter.Deserialize<dynamic>(result.Value); string md5 = resModel.data.md5; if (string.IsNullOrEmpty(md5)) { throw new Exception(result.Value); } else { //存储二维码逻辑 var saveResult = _orderCRepository.SaveQRCode(qrcodeid, id, md5, caCategory.ToString()); if (saveResult.WarnResult == null) { return new MQCode() { Md5 = md5, Faildate = saveResult.Value }; } else { return saveResult.WarnResult; } } } catch (Exception ex) { log.LogError("error(000010A692FD70000C05):", ex); return new WarnResult("生成二维码错误,请联系系统管理员。"); } } public class MQCode { /// <summary> /// 图片md5 /// </summary> public string Md5 { get; set; } /// <summary> /// 过期时间 /// </summary> public DateTime Faildate { get; set; } }
实现v2版本
调用小程序的生成二维码功能,小程序服务端提供了3种生成方式.
这里选择了getUnlimited接口,该接口没有调用数量限制,满足业务需求.
请发表评论