//获取当前已领取用户 public List <UserWeiXin> ReceiveUsers(string[] IDS) { string sql = @"select NickName,AddTime,UserImg,Price FROM UserRadomCoupons_wkn with(nolock) WHERE id=@id AND weixinID=@weixinID ORDER BY AddTime DESC"; System.Data.DataTable dt = SQLHelper.Get_DataTable(sql, SQLHelper.Open_Conn(conn), new Dictionary <string, DBParam> { { "id", new DBParam { ParamValue = IDS[1].ToString() } }, { "weixinID", new DBParam { ParamValue = IDS[0].ToString() } } }); List <UserWeiXin> List = new List <UserWeiXin>(); foreach (System.Data.DataRow row in dt.Rows) { UserWeiXin Item = new UserWeiXin(); Item.NickName = row["NickName"].ToString(); Item.AddTime = row["AddTime"].ToString(); Item.HeadImgUrl = row["UserImg"].ToString(); Item.Price = row["Price"].ToString(); List.Add(Item); } return(List); }
//拉去用户微信信息 public UserWeiXin UserInfo(string Code) { UserWeiXin weixin = new UserWeiXin(); weixin.Code = Code; string Url = @"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx6a8acea8df16a84b&secret=c8f1d6de36c0c75711a6052b3b3159b1&code=" + weixin.Code + @"&grant_type=authorization_code"; JObject json = GetJson(Url); weixin.Access_Token = json["access_token"].ToString().Trim().Replace("\"", ""); weixin.OpenId = json["openid"].ToString().Trim().Replace("\"", ""); Url = @"https://api.weixin.qq.com/sns/userinfo?access_token=" + weixin.Access_Token + "&openid=" + weixin.OpenId + "&lang=zh_CN"; JObject UserInfo = GetJson(Url); weixin.Province = UserInfo["province"].ToString(); weixin.City = UserInfo["city"].ToString(); weixin.Country = UserInfo["country"].ToString(); weixin.NickName = UserInfo["nickname"].ToString(); weixin.HeadImgUrl = UserInfo["headimgurl"].ToString(); weixin.Sex = UserInfo["sex"].ToString(); return(weixin); }
//整合随机获取的奖金信息 public Coupon_Random GetBonus(Coupon_Random CounponDetail, UserWeiXin User) { int MaxValue = CounponDetail.MaxReceive; int RandomMoney = new Random().Next(1, MaxValue); RandomMoney = CounponDetail.TotalAmount - CounponDetail.UsedAmount > RandomMoney ? RandomMoney : CounponDetail.TotalAmount - CounponDetail.UsedAmount; Coupon_Random Detail = new Coupon_Random(); Detail.id = CounponDetail.id; Detail.weixinID = CounponDetail.weixinID; Detail.Price = RandomMoney; Detail.sTime = CounponDetail.sTime; Detail.eTime = CounponDetail.eTime; Detail.weixinUserID = User.OpenId; Detail.Province = User.Province; Detail.City = User.City; Detail.Country = User.Country; Detail.NickName = User.NickName; Detail.UserImg = User.HeadImgUrl; Detail.Sex = User.Sex; return(Detail); }