public string CretaeWxCode() { var responseData = new ResponseData(); try { //微信 公共平台 var wapentity = new WApplicationInterfaceBLL(this.CurrentUserInfo).QueryByEntity(new WApplicationInterfaceEntity { CustomerId = this.CurrentUserInfo.ClientID, IsDelete = 0 }, null).FirstOrDefault(); //获取当前二维码 最大值 var MaxWQRCod = new WQRCodeManagerBLL(this.CurrentUserInfo).GetMaxWQRCod() + 1; if (wapentity == null || wapentity.ApplicationId == null) { responseData.success = false; responseData.msg = "无设置微信公众平台!"; return(responseData.ToJSON()); } string imageUrl = string.Empty; #region 生成二维码 JIT.CPOS.BS.BLL.WX.CommonBLL commonServer = new JIT.CPOS.BS.BLL.WX.CommonBLL(); imageUrl = commonServer.GetQrcodeUrl(wapentity.AppID.ToString().Trim() , wapentity.AppSecret.Trim() , "1", MaxWQRCod , this.CurrentUserInfo); if (string.IsNullOrEmpty(imageUrl)) { responseData.success = false; responseData.msg = "二维码生成失败!"; } else { string host = ConfigurationManager.AppSettings["DownloadImageUrl"]; CPOS.Common.DownloadImage downloadServer = new DownloadImage(); imageUrl = downloadServer.DownloadFile(imageUrl, host); } #endregion responseData.success = true; responseData.msg = "二维码生成成功!"; var rp = new ReposeData() { imageUrl = imageUrl, MaxWQRCod = MaxWQRCod }; responseData.data = rp; return(responseData.ToJSON()); } catch (Exception ex) { throw new APIException(ex.Message); } }
public WxCode CretaeWxCode() { var responseData = new WxCode(); responseData.success = false; responseData.msg = "二维码生成失败!"; var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo; try { //微信 公共平台 var wapentity = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity { CustomerId = loggingSessionInfo.ClientID, IsDelete = 0 }, null).FirstOrDefault(); //获取当前二维码 最大值 var MaxWQRCod = new WQRCodeManagerBLL(loggingSessionInfo).GetMaxWQRCod() + 1; if (wapentity == null) { responseData.success = false; responseData.msg = "无设置微信公众平台!"; return(responseData); } string imageUrl = string.Empty; #region 生成二维码 JIT.CPOS.BS.BLL.WX.CommonBLL commonServer = new JIT.CPOS.BS.BLL.WX.CommonBLL(); try { imageUrl = commonServer.GetQrcodeUrl(wapentity.AppID.ToString().Trim() , wapentity.AppSecret.Trim() , "1", MaxWQRCod , loggingSessionInfo); } catch (Exception e) { responseData.success = false; responseData.msg = e.Message;// "二维码生成失败!"; return(responseData); } if (!string.IsNullOrEmpty(imageUrl)) { string host = ConfigurationManager.AppSettings["DownloadImageUrl"]; CPOS.Common.DownloadImage downloadServer = new DownloadImage(); imageUrl = downloadServer.DownloadFile(imageUrl, host); } #endregion responseData.success = true; responseData.msg = ""; responseData.ImageUrl = imageUrl; responseData.MaxWQRCod = MaxWQRCod; return(responseData); } catch (Exception ex) { //throw new APIException(ex.Message); return(responseData); } }
protected override DownloadQRCodeRD ProcessRequest(DTO.Base.APIRequest <DownloadQRCodeRP> pRequest) { string content = string.Empty; string customerId = string.Empty; var RD = new DownloadQRCodeRD(); try { #region 解析传入参数 //解析请求字符串 var RP = pRequest.Parameters; //判断客户ID是否传递 customerId = CurrentUserInfo.CurrentUser.customer_id; #endregion var imageUrl = string.Empty; Random ro = new Random(); var iUp = 100000000; var iDown = 50000000; if (string.IsNullOrEmpty(RP.VipDCode.ToString()) || RP.VipDCode == 0) { throw new APIException("VipDCode参数不能为空"); } var rpVipDCode = 0; //临时二维码 var iResult = ro.Next(iDown, iUp); //随机数 if (RP.VipDCode == 9) //永久二维码 { var userQRCodeBll = new WQRCodeManagerBLL(CurrentUserInfo); var marketEventBll = new MarketEventBLL(CurrentUserInfo); var marketEventEntity = marketEventBll.QueryByEntity(new MarketEventEntity() { EventCode = "CA00002433", CustomerId = CurrentUserInfo.ClientID }, null).FirstOrDefault(); var userQRCode = userQRCodeBll.QueryByEntity(new WQRCodeManagerEntity() { ObjectId = marketEventEntity.MarketEventID, CustomerId = CurrentUserInfo.ClientID }, null); // if (userQRCode != null && userQRCode.Length > 0) { RD.imageUrl = userQRCode[0].ImageUrl; return(RD); } //获取当前二维码 最大值 iResult = new WQRCodeManagerBLL(CurrentUserInfo).GetMaxWQRCod() + 1; rpVipDCode = 1; //永久 #region 获取微信帐号 //门店关联的公众号 var tueBll = new TUnitExpandBLL(CurrentUserInfo); var tueEntity = new TUnitExpandEntity(); if (!string.IsNullOrEmpty(CurrentUserInfo.CurrentUserRole.UnitId)) { tueEntity = tueBll.QueryByEntity(new TUnitExpandEntity() { UnitId = CurrentUserInfo.CurrentUserRole.UnitId }, null).FirstOrDefault(); } var server = new WApplicationInterfaceBLL(CurrentUserInfo); var wxObj = new WApplicationInterfaceEntity(); if (tueEntity != null && !string.IsNullOrEmpty(tueEntity.Field1)) { wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { AppID = tueEntity.Field1, CustomerId = customerId }, null).FirstOrDefault(); } else { wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { CustomerId = customerId }, null).FirstOrDefault(); } if (wxObj == null) { throw new APIException("没有对应公众号"); } else { var commonServer = new CommonBLL(); imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID , wxObj.AppSecret , rpVipDCode.ToString("") //二维码类型 0: 临时二维码 1:永久二维码 , iResult, CurrentUserInfo); //iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000 if (imageUrl != null && !imageUrl.Equals("")) { CPOS.Common.DownloadImage downloadServer = new DownloadImage(); string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"]; imageUrl = downloadServer.DownloadFile(imageUrl, downloadImageUrl); //如果名称不为空,就把图片放在一定的背景下面 //if (!string.IsNullOrEmpty(RP.Parameters.RetailTraderName)) //{ // string apiDomain = ConfigurationManager.AppSettings["website_url"]; // imageUrl = CombinImage(apiDomain + @"/HeadImage/qrcodeBack.jpg", imageUrl, RP.Parameters.RetailTraderName + "合作二维码"); //} } } #endregion if (!string.IsNullOrEmpty(imageUrl)) //永久二维码 { #region 创建店员永久二维码匹配表 var userQrTypeBll = new WQRCodeTypeBLL(CurrentUserInfo); var userQrType = userQrTypeBll.QueryByEntity(new WQRCodeTypeEntity() { TypeName = "签到" }, null); //"UserQrCode" if (userQrType != null && userQrType.Length > 0) { var userQrCodeBll = new WQRCodeManagerBLL(CurrentUserInfo); var userQrCode = new WQRCodeManagerEntity(); userQrCode.QRCode = iResult.ToString();//记录传过去的二维码场景值 userQrCode.QRCodeTypeId = userQrType[0].QRCodeTypeId; userQrCode.IsUse = 1; userQrCode.CustomerId = CurrentUserInfo.CurrentUser.customer_id; userQrCode.ImageUrl = imageUrl; userQrCode.ApplicationId = wxObj.ApplicationId; //objectId 为店员ID userQrCode.ObjectId = marketEventEntity.MarketEventID; userQrCodeBll.Create(userQrCode); } #endregion } } RD.imageUrl = imageUrl; } catch { throw new APIException("生成二维码错误"); } return(RD); }
public HttpResponseMessage QRCode(string UnitId, string ObjectID) { Loggers.Debug(new DebugLogInfo() { Message = $"[api/Vip/QRCode]接口,参数:\"UnitId:{UnitId}&ObjectID:{ObjectID}\"" }); try { string customerId = ConfigurationManager.AppSettings["CustomerId"].Trim(); var loggingSessionInfo = Default.GetLoggingSession(customerId, ObjectID); loggingSessionInfo.Conn = ConfigurationManager.AppSettings["Conn"].Trim(); var imageUrl = string.Empty; Random ro = new Random(); var iUp = 100000000; var iDown = 50000000; var rpVipDCode = 0; //临时二维码 var iResult = ro.Next(iDown, iUp); //随机数 string objectid = ObjectID; #region 获取微信帐号 //门店关联的公众号 var tuBll = new t_unitBLL(loggingSessionInfo); var tuEntity = new t_unitEntity(); if (!string.IsNullOrEmpty(UnitId)) { tuEntity = tuBll.QueryByEntity(new t_unitEntity() { unit_id = UnitId }, null) .FirstOrDefault(); } var server = new WApplicationInterfaceBLL(loggingSessionInfo); var wxObj = new WApplicationInterfaceEntity(); if (tuEntity != null && !string.IsNullOrEmpty(tuEntity.weiXinId)) { wxObj = server.QueryByEntity( new WApplicationInterfaceEntity { WeiXinID = tuEntity.weiXinId, CustomerId = customerId }, null).FirstOrDefault(); } else { wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { CustomerId = customerId }, null) .FirstOrDefault(); } if (wxObj == null) { throw new APIException("不存在对应的微信帐号") { ErrorCode = 302 }; } else { var commonServer = new CommonBLL(); imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID , wxObj.AppSecret , rpVipDCode.ToString("") //二维码类型 0: 临时二维码 1:永久二维码 , iResult, loggingSessionInfo); //iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000 //"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA=="; //"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA=="; if (imageUrl != null && !imageUrl.Equals("")) { DownloadImage downloadServer = new DownloadImage(); string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"]; imageUrl = downloadServer.DownloadFile(imageUrl, downloadImageUrl); } } #endregion #region 创建临时匹配表 VipDCodeBLL vipDCodeServer = new VipDCodeBLL(loggingSessionInfo); VipDCodeEntity info = new VipDCodeEntity(); info.DCodeId = iResult.ToString(); //记录传过去的二维码场景值****(保存到数据库时没加空格) info.CustomerId = customerId; info.UnitId = UnitId; //获取会集店 info.Status = "0"; info.IsReturn = 0; info.DCodeType = 2; // add by donal 2014-9-22 10:02:08 loggingSessionInfo.UserID = ObjectID; info.CreateBy = ObjectID; info.ImageUrl = imageUrl; //info.VipId = RP.UserID; info.ObjectId = ObjectID; //分享经销商的vipid vipDCodeServer.Create(info); #endregion var model = new QRCodeResponseModel() { IsSucess = true, ImageUrl = imageUrl, paraTmp = iResult.ToString().Insert(4, " ") }; Loggers.Debug(new DebugLogInfo() { Message = $"setSignUp content: {model}" }); return(Request.CreateResponse(HttpStatusCode.OK, model)); } catch (Exception ex) { var model = new QRCodeResponseModel() { IsSucess = false, ErrorMessage = string.Format("获取二维码出错:{0}", ex.Message) }; Loggers.Debug(new DebugLogInfo() { Message = string.Format("获取二维码出错:{0}", ex.Message) }); return(Request.CreateResponse(HttpStatusCode.InternalServerError, model)); } }
/// <summary> /// 获取门店二维码 /// </summary> /// <returns></returns> public string SetUnitWXCode() { #region 参数处理 string WeiXinId = Request("WeiXinId"); string UnitId = Request("UnitId"); string WXCode = Request("WXCode"); var responseData = new ResponseData(); if (WeiXinId == null || WeiXinId.Trim().Length == 0) { responseData.success = false; responseData.msg = "公众号不能为空"; return(responseData.ToJSON()); } //if (UnitId == null || UnitId.Trim().Length == 0) //{ // responseData.success = false; // responseData.msg = "门店标识不能为空"; // return responseData.ToJSON(); //} //if (WXCode == null || WXCode.Equals("")) //{ // VwUnitPropertyBLL unitServer = new VwUnitPropertyBLL(CurrentUserInfo); // WXCode = unitServer.GetUnitWXCode(UnitId).ToString(); //} #endregion #region 获取微信公众号信息 WApplicationInterfaceBLL server = new WApplicationInterfaceBLL(CurrentUserInfo); var wxObj = server.QueryByEntity(new WApplicationInterfaceEntity { CustomerId = CurrentUserInfo.CurrentUser.customer_id , IsDelete = 0 , ApplicationId = WeiXinId }, null); if (wxObj == null || wxObj.Length == 0) { responseData.success = false; responseData.msg = "不存在对应的微信帐号"; return(responseData.ToJSON().ToString()); } else { JIT.CPOS.BS.BLL.WX.CommonBLL commonServer = new JIT.CPOS.BS.BLL.WX.CommonBLL(); string imageUrl = commonServer.GetQrcodeUrl(wxObj[0].AppID.ToString().Trim() , wxObj[0].AppSecret.Trim() , "1" , Convert.ToInt32(WXCode), CurrentUserInfo); if (imageUrl != null && !imageUrl.Equals("")) { string host = ConfigurationManager.AppSettings["DownloadImageUrl"]; try { CPOS.Common.DownloadImage downloadServer = new DownloadImage(); imageUrl = downloadServer.DownloadFile(imageUrl, host); responseData.success = true; responseData.msg = imageUrl; responseData.status = WXCode; } catch (Exception ex) { responseData.success = false; responseData.data = imageUrl; responseData.msg = ex.ToString(); return(responseData.ToJSON().ToString()); } return(responseData.ToJSON().ToString()); } else { responseData.success = false; responseData.msg = "图片不存在"; return(responseData.ToJSON().ToString()); } } #endregion }
protected override GetVipDealerSpreadCodeRD ProcessRequest(DTO.Base.APIRequest <GetVipDealerSpreadCodeRP> pRequest) { var rd = new GetVipDealerSpreadCodeRD(); var VipBLL = new VipBLL(CurrentUserInfo); var WQRCodeManagerBLL = new WQRCodeManagerBLL(this.CurrentUserInfo); var WQRCodeTypeBLL = new WQRCodeTypeBLL(this.CurrentUserInfo); try { var UserID = pRequest.UserID; // string imageUrl = string.Empty; string QRCodeId = string.Empty; string VipName = string.Empty; string HeadImgUrl = string.Empty; //分享处理 if (!string.IsNullOrWhiteSpace(pRequest.Parameters.ShareUserId)) { UserID = pRequest.Parameters.ShareUserId; } //微信 公共平台 var wapentity = new WApplicationInterfaceBLL(this.CurrentUserInfo).QueryByEntity(new WApplicationInterfaceEntity { CustomerId = this.CurrentUserInfo.ClientID, IsDelete = 0 }, null).FirstOrDefault(); var VipDealerType = WQRCodeTypeBLL.QueryByEntity(new WQRCodeTypeEntity() { TypeCode = "VipDealerCode" }, null).FirstOrDefault(); if (VipDealerType == null) { throw new APIException("静态二位经销商类型无此类型!"); } if (!string.IsNullOrWhiteSpace(pRequest.Parameters.QRCodeId)) { #region 分享出去的二维码 var WQRCodeManagerData = WQRCodeManagerBLL.GetByID(pRequest.Parameters.QRCodeId); if (WQRCodeManagerData == null) { throw new APIException("此二维码不存在!"); } var VipData = VipBLL.GetByID(WQRCodeManagerData.ObjectId); if (VipData == null) { throw new APIException("此二维码会员不存在!"); } //二维码图片地址,ID赋值,会员名称,头像地址赋值 imageUrl = WQRCodeManagerData.ImageUrl; QRCodeId = WQRCodeManagerData.QRCodeId.ToString(); VipName = VipData.VipName; HeadImgUrl = VipData.HeadImgUrl; #endregion } else { #region 获取去自己静态推广二维码 var WQRCodeManagerData = WQRCodeManagerBLL.QueryByEntity(new WQRCodeManagerEntity() { ObjectId = UserID, QRCodeTypeId = VipDealerType.QRCodeTypeId }, null).FirstOrDefault(); if (WQRCodeManagerData != null) { //二维码图片地址,ID赋值 imageUrl = WQRCodeManagerData.ImageUrl; QRCodeId = WQRCodeManagerData.QRCodeId.ToString(); } else { //获取当前二维码 最大值 var MaxWQRCod = new WQRCodeManagerBLL(this.CurrentUserInfo).GetMaxWQRCod() + 1; if (wapentity == null) { throw new APIException("无设置微信公众平台!"); } #region 生成二维码 JIT.CPOS.BS.BLL.WX.CommonBLL commonServer = new JIT.CPOS.BS.BLL.WX.CommonBLL(); imageUrl = commonServer.GetQrcodeUrl(wapentity.AppID.ToString().Trim() , wapentity.AppSecret.Trim() , "1", MaxWQRCod , this.CurrentUserInfo); if (string.IsNullOrEmpty(imageUrl)) { throw new APIException("二维码生成失败!"); } else { string host = ConfigurationManager.AppSettings["original_url"]; CPOS.Common.DownloadImage downloadServer = new DownloadImage(); //二维码赋值 imageUrl = downloadServer.DownloadFile(imageUrl, host); if (!string.IsNullOrEmpty(UserID)) { var WQRQrCode = new WQRCodeManagerEntity(); WQRQrCode.QRCodeId = Guid.NewGuid(); WQRQrCode.QRCode = MaxWQRCod.ToString(); WQRQrCode.QRCodeTypeId = VipDealerType.QRCodeTypeId; WQRQrCode.IsUse = 1; WQRQrCode.CustomerId = this.CurrentUserInfo.ClientID; WQRQrCode.ImageUrl = imageUrl; WQRQrCode.ApplicationId = wapentity.ApplicationId;//微信公众号的编号 //objectId 为会员ID WQRQrCode.ObjectId = UserID; WQRCodeManagerBLL.Create(WQRQrCode); //二维码ID赋值 QRCodeId = WQRQrCode.QRCodeId.ToString(); } } #endregion } //会员名称,头像地址 var VipData = VipBLL.GetByID(UserID); if (VipData == null) { throw new APIException("会员不存在!"); } VipName = VipData.VipName; HeadImgUrl = VipData.HeadImgUrl; #endregion } //响应参数赋值 rd.imageUrl = imageUrl; rd.VipName = VipName; rd.HeadImgUrl = HeadImgUrl; rd.QRCodeId = QRCodeId; } catch (Exception ex) { throw new APIException(ex.Message); } return(rd); }
public string SetVipInfoByToken(string token, string openId, LoggingSessionInfo loggionSesionInfo, HttpResponse Response) { string vipId = string.Empty; var url = "https://api.weixin.qq.com/sns/userinfo?"; var postData = "access_token=" + token + "&openid=" + openId + "&lang=zh_CN"; // Response.Write(url + postData); string method = "GET"; // var data = HttpWebClient.DoHttpRequest(url, postData); var data = CommonBLL.GetRemoteData(url + postData, method, string.Empty); var openInfo = data.DeserializeJSONTo <WxOpenInfoResponse>(); if (openInfo == null) { Loggers.Debug(new DebugLogInfo() { Message = "获取微信用户信息失败:" + data.ToJSON() }); return(vipId); } else { try { //insert into vip CPOS.Common.DownloadImage downloadServer = new DownloadImage(); string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"]; var headimgurl = downloadServer.DownloadFile(openInfo.headimgurl, downloadImageUrl); vipId = BaseService.NewGuidPub(); VipBLL vipServiceUnion = new VipBLL(loggionSesionInfo); var vipInfo = new VipEntity(); vipInfo.VIPID = vipId; vipInfo.WeiXinUserId = openId; //openId微信提供 vipInfo.City = openInfo.city; //城市,微信提供 vipInfo.Gender = Convert.ToInt32(openInfo.sex); //性别,微信提供 vipInfo.VipName = openInfo.nickname; //微信昵称,微信提供 vipInfo.VipCode = vipServiceUnion.GetVipCode(); vipInfo.UnionID = openInfo.unionid; vipInfo.VipSourceId = "3"; //写死 vipInfo.HeadImgUrl = headimgurl; //注意,需要先传到我们本地服务器,可以参考(需要download下来) vipInfo.ClientID = loggionSesionInfo.ClientID; //客户标识 vipInfo.RegistrationTime = DateTime.Now; vipInfo.Status = 0; //客户没有关注 vipInfo.VipPasswrod = "e10adc3949ba59abbe56e057f20f883e"; //初始密码123456 UnitService unitServer = new UnitService(loggionSesionInfo); vipInfo.CouponInfo = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识 var wappBll = new WApplicationInterfaceBLL(loggionSesionInfo); string weixinId = ""; var wappEntity = wappBll.QueryByEntity(new WApplicationInterfaceEntity() { CustomerId = loggionSesionInfo.ClientID }, null); if (wappEntity.Length > 0) { weixinId = wappEntity[0].WeiXinID; } vipInfo.WeiXin = weixinId; //微信号码,通过数据库可以查出 vipServiceUnion.Create(vipInfo); } catch (Exception ex) { Loggers.Debug(new DebugLogInfo() { Message = "新增微信用户信息失败:" + ex.ToString() }); } return(vipId); } }