public int SaveArInfo(AR_QR_FANS entity) { if (entity.ID > 0) { return(_set.Update(entity)); } else { return((int)_set.Insert(entity)); } }
public int GetMaxArid() { int ewmId = 0; AR_QR_FANS ar = _set.GetMaxArid(); ewmId = ar.AR_ID.Value; if (ewmId > 9999) { ewmId = 0; } return(ewmId); }
public int IsExpire(int ar_id) { int return_id = 0; AR_QR_FANS arinfo = SystemService.QueryArInfoByArId(ar_id); if (arinfo != null) { DateTime t0 = arinfo.CREATE_DATE.Value; DateTime t1 = DateTime.Now; // 求时间差 TimeSpan ts = t1 - t0; if (arinfo.EXPIRE_SECONDS < ts.TotalSeconds)//如果已过期才能用 { //删除过期的记录 int des = SystemService.DeleteAr(arinfo.ID); } } return(return_id); }
public ActionResult GetOpenid(int id) { JsonSMsg rMsg = new JsonSMsg(); string openid = "1111"; //获取openid AR_QR_FANS ar = SystemService.QueryArInfo(id); if (ar != null) { openid = ar.OPENID; rMsg.Status = 1; rMsg.Message = "成功"; rMsg.Data = openid; } else { rMsg.Status = 0; rMsg.Message = "失败"; } return(Json(rMsg)); }
public ActionResult SendImage() { JsonSMsg rMsg = new JsonSMsg(); try { int ar_id = SystemService.GetMaxArid() + 1; string file_path = ""; string expire = AppConfig.ExpireAr;//该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 AR_QR_FANS ar = new AR_QR_FANS(); //获取图片流存到本地 file_path = GetImageStreem(); //上传本地图片到微信服务器 string url = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", new WeiPage().Token(AppConfig.FWHOriginalID), "image"); string json = Utility.HttpUploadFile(url, file_path); mediainfo media = JsonConvert.DeserializeObject <mediainfo>(json); //删除临时图片 if (media != null) { System.IO.File.Delete(file_path); } //获取临时二维码 QRCodeResponse respons = WXMPClientServiceApi.Create().CreateTempQRCode(new WeiPage().Token(AppConfig.FWHOriginalID), ar_id, expire); string qr_url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + respons.Ticket; //保存到数据库 //AR_QR_FANS arinfo = SystemService.QueryArInfoByArId(ar_id); //if (arinfo != null) //{ // ar = arinfo; //} ar.AR_ID = ar_id; ar.AR_URL = qr_url; ar.MEDIA_ID = media.media_id; ar.EXPIRE_SECONDS = int.Parse(expire); ar.CREATE_DATE = DateTime.Now; int res = SystemService.SaveArInfo(ar); if (res > 0) { arinfo ars = new arinfo(); ars.id = res; ars.url = qr_url; rMsg.Status = 1; rMsg.Message = "成功"; rMsg.Data = res + "|" + qr_url; } else { rMsg.Status = 0; rMsg.Message = "失败"; } } catch (Exception ex) { rMsg.Status = 0; rMsg.Message = "SendImage报错:" + ex.Message; } return(Json(rMsg)); }