// GET api/<controller> /// <summary> /// 线下客户端获取微信登录二维码 /// </summary> /// <returns></returns> public JsonResult <string> Get(string lockCode) { JsonResult <string> result = new JsonResult <string>(); result.code = 0; result.msg = "OK"; string uuid = Utils.GetWeChatUUID(); string long_url = WeChateSiteHelper.getCRContent(uuid); string cqContent = WeChatAccessTokenAPI.GetShortURL(long_url); if (string.IsNullOrEmpty(cqContent)) { cqContent = long_url; } string fileName = string.Format("{0}.png", uuid); string filePath = FileHelper.GetPicFilePath(fileName); if (QrCodeHelper.CreateImgCode(cqContent, filePath)) { result.code = 1; result.Result = FileHelper.GetPicFileURL(fileName); result.ResultMsg = uuid; ThreadPool.QueueUserWorkItem(new WaitCallback(p => { //图片记录进缓存,定期清理 string key = CacheKey.GetQrCodeKey(DateTime.Now); RedisBase.List_Add <string>(key, filePath); RedisBase.List_SetExpire(key, DateTime.Now.AddDays(2)); //记录日志 WeChatLogin login = new WeChatLogin(); login.State = 0; login.UUID = uuid; login.LoginData = DateTime.Now.ToString("yyyy-MM-dd"); login.CreateTime = DateTime.Now; login.LockCode = lockCode; SaveWeChatLogin(login); }), null); } return(result); }
public async Task <IHttpActionResult> EvaluationResultShare(string id) { JsonResult <string> result = new JsonResult <string>(); result.code = 1; result.msg = "OK"; await Task.Run(() => { string filename = string.Format("ER{0}.png", id); string filepath = Path.Combine(SystemSet.ResourcesPath, SystemSet.QrCodePic, filename); if (!File.Exists(filepath)) { string dir = Path.GetDirectoryName(filepath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string qrcode = ShareQrCodeContent.EvaluationResultShareQrCodeContent(id); QrCodeHelper.CreateImgCode(qrcode, filepath); } result.Result = string.Format("{0}/{1}/{2}", SystemSet.WebResourcesSite, SystemSet.QrCodePic, filename); }); return(Ok(result)); }
public async Task <IHttpActionResult> BindingWeChartCQ() { JsonResult <string> result = new JsonResult <string>(); result.code = 0; result.msg = "OK"; await Task.Run(() => { string uuid = Utils.GetWeChatUUID(); string long_url = WeChateSiteHelper.getCRContent(uuid); string cqContent = WeChatAccessTokenAPI.GetShortURL(long_url); if (string.IsNullOrEmpty(cqContent)) { cqContent = long_url; } string fileName = string.Format("{0}.png", uuid); string filePath = FileHelper.GetPicFilePath(fileName); if (QrCodeHelper.CreateImgCode(cqContent, filePath)) { result.code = 1; result.Result = FileHelper.GetPicFileURL(fileName); result.ResultMsg = uuid; //图片记录进缓存,定期清理 string key = CacheKey.GetQrCodeKey(DateTime.Now); RedisBase.List_Add <string>(key, filePath); RedisBase.List_SetExpire(key, DateTime.Now.AddDays(2)); ApiUserManager userManager = new ApiUserManager(ActionContext); string bindkey = string.Format("bind_{0}", uuid); RedisBase.Item_Set(bindkey, userManager.User); RedisBase.ExpireEntryAt(bindkey, DateTime.Now.AddHours(1)); } }); return(Ok(result)); }
public JsonResult <PayOrder> Post(UnifiedOrder obj) { ClassLoger.Info("PayController.Post", obj.PayTyp.ToString(), obj.product_id, obj.productType.TryToString()); JsonResult <PayOrder> result = new JsonResult <PayOrder>(); result.code = 1; result.msg = "OK"; PayOrderBll porderbll = new PayOrderBll(); try { if (obj.PayTyp == 1) { JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = ""; if (!obj.openid.IsNull()) { WeChatUserBll wuserbll = new WeChatUserBll(); WeChatUser wuser = wuserbll.GetWeChatUserByUnionID(obj.openid); jsApiPay.openid = wuser.ServiceOpenID; } else if (!obj.userid.IsNull()) { UserInfoBll ubll = new UserInfoBll(); var user = ubll.GetUserinfoByID(obj.userid); if (!user.Openid.IsNull()) { WeChatUserBll wuserbll = new WeChatUserBll(); WeChatUser wuser = wuserbll.GetWeChatUserByUnionID(user.Openid); jsApiPay.openid = wuser.ServiceOpenID; } } jsApiPay.total_fee = 1; jsApiPay.trade_type = obj.trade_type; if (obj.productType == 1) { //查询商品信息,获取商品价格 double Price = 0.1; jsApiPay.total_fee = (Price * 100).TryToInt(); jsApiPay.body = "商品名称"; } jsApiPay.attach = "北京xx"; string out_trade_no = porderbll.GetOnlineOrder(PayTypeEnum.WeChart); jsApiPay.out_trade_no = out_trade_no; jsApiPay.product_id = obj.product_id; ClassLoger.Info("api/Pay/UnifiedOrder", "total_fee", jsApiPay.total_fee.ToString()); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); PayOrder porder = new PayOrder(); if (unifiedOrderResult.GetValue("return_code").TryToString() == "SUCCESS" && unifiedOrderResult.GetValue("result_code").TryToString() == "SUCCESS") { if (unifiedOrderResult.IsSet("code_url")) { string code_url = unifiedOrderResult.GetValue("code_url").TryToString(); string filename = string.Format("WXPY{0}.png", code_url.MD5()); string filepath = Path.Combine(SystemSet.ResourcesPath, SystemSet.QrCodePic, filename); if (!File.Exists(filepath)) { QrCodeHelper.CreateImgCode(code_url, filepath); } porder.code_url = Path.Combine(SystemSet.WebResourcesSite, SystemSet.QrCodePic, filename); } porder.OnlineOrder = out_trade_no; porder.openid = obj.openid; porder.PayState = PayStateEnum.Unpaid; porder.PayType = PayTypeEnum.WeChart; porder.prepay_id = unifiedOrderResult.GetValue("prepay_id").TryToString(); porder.product_id = obj.product_id; porder.total_fee = jsApiPay.total_fee; porder.trade_type = obj.trade_type; porder.CreateTime = DateTime.Now; porder.UserID = obj.userid; porder.ID = porderbll.AddPayOrder(porder); result.Result = porder; return(result); } else { result.code = 0; result.msg = unifiedOrderResult.GetValue("return_code").TryToString(); result.ResultMsg = unifiedOrderResult.GetValue("result_code").TryToString(); } } } catch (Exception ex) { result.code = -1; result.msg = "PayController.unifiedorder:" + ex.Message; } return(result); }