public IHttpActionResult PutPassword(string v1, string username, string password, string code) { try { if (isNUll(username, password, code)) { return(invildRequest("参数不能为空")); } //objectId var dir = bll.QuerySingleByWheres(new List <Wheres> { new Wheres("username", "=", username) }); if (dir == null) { return(notFound("用户不存在")); } string objectId = dir.objectId; //验证手机验证码 MvcApplication1.Utility.HttpClient client = new MvcApplication1.Utility.HttpClient("https://webapi.sms.mob.com"); string postUri = "sms/verify?appkey=1ad08332b2ac0&phone=" + username + "&zone=86&code=" + code; //string userJson = @"{""appkey"":""1ad08332b2ac0"",""phone"":" + username + @",""zone"":""86"",""code"":" + code + "}"; //请求验证 string postResponse = client.Get(postUri); if (!string.IsNullOrEmpty(postResponse)) { JObject jo = JsonHelper.DeserializeObject(postResponse); string status = jo["status"].ToString(); if (!status.Equals("200")) { return(notFound("验证码错误" + postResponse)); } } else { return(notFound("验证码请求验证失败")); } //更新时间 DateTime dt = DateTime.Now; //更新 bool result = bll.UpdateByWheres(new Wheres("username", "=", username), new Dictionary <string, object> { { "password", (password + objectId).Md5() }, { "updatedAt", dt } }); if (result) { return(ok(new { updateAt = dt.ToString("yyyy-MM-dd HH:mm:ss") })); } return(notFound("修改失败")); } catch (Exception e) { return(execept(e.Message)); } }
public IHttpActionResult PostMessage(string v1, [FromBody] Message model) { try { //{"_User":{"objectId":"556fb922-de5c-4086-a489-9f09799a5456"},"isReaded":false,"msg":"还看呢","toldId":"556fb922-de5c-4086-a489-9f09799a5456"} //表单验证 if (isNUll(model._User.objectId, model.msg, model.toldId)) { return(invildRequest("参数不能为空")); } //主键 Guid guid = Guid.NewGuid(); model.objectId = guid.ToString(); //时间 model.createdAt = DateTime.Now; model.updatedAt = DateTime.Now; bool result = bll.Insert(model); if (result) { //return ok(model.updatedAt.ToString("yyyy-mm-dd HH:mm:ss")); DateTime start = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); DateTime now = DateTime.Now; TimeSpan toNow = now.Subtract(start); string timeStamp = toNow.Ticks.ToString(); timeStamp = timeStamp.Substring(0, timeStamp.Length - 7); string type = "push/single_account"; string message_type = "1"; var body = new { content = model.msg, title = "消息", vibrate = 1 }; //string objectId = HttpContext.Current.Request.Headers["objectId"]; //string objectId = "844b0bf2-d4a6-418b-a327-cb7d4f72a0fa"; string url = "access_id=2100180778&account=" + model.toldId + "&message=" + JsonHelper.Serialize(body) + "&message_type=" + message_type + "×tamp=" + timeStamp; string encode = string.Format("POSTopenapi.xg.qq.com/v2/{0}{1}0537318f3b4384e6c74e8396ef9122a4", type, url.Replace("&", "")); string ss = url + "&sign=" + encode.Md5(); MvcApplication1.Utility.HttpClient p = new MvcApplication1.Utility.HttpClient("http://openapi.xg.qq.com/v2"); return(create(p.Post(ss, type))); } return(notFound("注册失败")); } catch (Exception e) { return(execept(e.Message)); } }
public IHttpActionResult GetMassMessage(string v1, string phone) { //短信请求前,检查用户是否已经绑定 _UserBLL bll = new _UserBLL(); if (isNUll(phone)) { return(notFound("手机号不能为空")); } if (bll.QueryBandByUsername(phone)) { return(notFound("手机号已绑定过")); } MvcApplication1.Utility.HttpClient client = new MvcApplication1.Utility.HttpClient("https://webapi.sms.mob.com"); string postUri = "sms/sendmsg?appkey=1077112ae0d07&phone=" + phone + "&zone=86"; string postResponse = client.Get(postUri); if (!string.IsNullOrEmpty(postResponse)) { JObject jo = JsonHelper.DeserializeObject(postResponse); string status = jo["status"].ToString(); if (status.Equals("200")) { return(ok("请求验证码成功")); } else { return(notFound("请求验证码失败" + postResponse)); } } else { return(notFound("验证码请求失败")); } }
/// <summary> /// 手机端注册邀请接口 /// </summary> /// <param name="v1"></param> /// <param name="model"></param> /// <param name="code"></param> /// <param name="inviteCode">邀请人手机号码</param> /// <returns></returns> public IHttpActionResult Post(string v1, [FromBody] _User model, string code, string inviteCode = "") { bool isInvited = false; try { //表单验证 if (isNUll(model.username, model.password, code)) { return(invildRequest("参数不能为空")); } //判断是否有邀请码 if (!string.IsNullOrEmpty(inviteCode)) { //邀请人手机号码是否存在 if (!bll.QueryExitByUsername(inviteCode)) { return(notFound("邀请人手机号码不存在哦!")); } isInvited = true; } //手机端短信验证 string postUri = "sms/verify?appkey=1ad08332b2ac0&phone=" + model.username + "&zone=86&code=" + code; //短信验证 MvcApplication1.Utility.HttpClient client = new MvcApplication1.Utility.HttpClient("https://webapi.sms.mob.com"); //请求验证 string postResponse = client.Get(postUri); if (!string.IsNullOrEmpty(postResponse)) { JObject jo = JsonHelper.DeserializeObject(postResponse); string status = jo["status"].ToString(); if (!status.Equals("200")) { return(notFound("验证码错误" + postResponse)); } } else { return(notFound("验证码请求验证失败")); } //查询用户是否已经存在 if (bll.QueryExitByUsername(model.username)) { return(notFound("用户名已存在")); } bool result = false; //主键 Guid guid = Guid.NewGuid(); DateTime dt = DateTime.Now; model.objectId = guid.ToString(); //密码加盐保存 model.password = (model.password + model.objectId).Md5(); //初始化数据 model.nickname = "口袋爆料人"; model.credit = 40; model.overage = 0; model.sign_in = true; model.shake_times = 3; model.createdAt = dt; model.updatedAt = dt; string initPassword = "******"; model.transaction_password = (initPassword.Md5() + model.objectId).Md5(); //注册积分记录 CreditsHistory history1 = new CreditsHistory(); history1.objectId = guid.ToString(); history1.createdAt = dt; history1.updatedAt = dt; history1.change = 40; history1.credit = 40; history1.type = 4;//注册得积分 result = bll.Insert1(model, history1); if (isInvited) { List <Wheres> whs = new List <Wheres>() { new Wheres("username", "=", inviteCode) }; _User user = bll.QuerySingleByWheres(whs); //邀请积分记录 CreditsHistory history2 = new CreditsHistory(); Guid guid1 = Guid.NewGuid(); history2.objectId = guid1.ToString(); history2.createdAt = dt; history2.updatedAt = dt; history2.type = 3;//邀请得积分 history2.change = 30; history2.credit = user.credit + 30; history2.userId = user.objectId; result = bll.Insert1(model, history1, history2, inviteCode); } if (result) { return(ok(new { msg = "注册成功" })); } return(notFound("注册失败")); } catch (Exception e) { return(execept(e.Message)); } }
/// <summary> /// 微信端注册与绑定接口 /// </summary> /// <param name="v1"></param> /// <param name="model"></param> /// <param name="code"></param> /// <param name="wechat"></param> /// <returns></returns> public IHttpActionResult Post(string v1, [FromBody] _User model, string code, bool wechat) { try { //表单验证 if (isNUll(model.username, model.password, code)) { return(invildRequest("参数不能为空")); } //注册流程 wechat chat = new wechat(); //主键 Guid guid = Guid.NewGuid(); //判断是否有openId if (model.authData == null || model.authData.wechat == null || isNUll(model.authData.wechat.openId)) { return(invildRequest("参数有误")); } //微信端短信验证 MvcApplication1.Utility.HttpClient client = new MvcApplication1.Utility.HttpClient("https://webapi.sms.mob.com"); string postUri = "sms/checkcode?appkey=1077112ae0d07&phone=" + model.username + "&zone=86&code=" + code; //string userJson = @"{""appkey"":""1ad08332b2ac0"",""phone"":" + model.username + @",""zone"":""86"",""code"":" + code + "}"; //请求验证 string postResponse = client.Get(postUri); if (!string.IsNullOrEmpty(postResponse)) { JObject jo = JsonHelper.DeserializeObject(postResponse); string status = jo["status"].ToString(); if (!status.Equals("200")) { return(notFound("验证码错误")); } } else { return(notFound("验证码请求验证失败")); } //判断微信号是否绑定过 if (wechat_bll.QueryExitByOpenId(model.authData.wechat.openId)) { return(notFound("此微信号已经绑定过了哦!")); } //注册与绑定逻辑 model.authData.objectId = guid.ToString(); model.authData.wechat.objectId = guid.ToString(); //判断用户是否存在 if (bll.QueryExitByUsername(model.username)) { //用户已存在 //微信绑定操作 //更新openId和inopenId //邀请码选填 if (isNUll(model.authData.wechat.inopenId)) { //邀请码为空,绑定 if (bll.UpdateInsert1(model)) { return(ok(new { msg = "绑定成功" })); } return(notFound("绑定失败")); } //邀请码不为空 if (!bll.QueryExitByUsername(model.authData.wechat.inopenId)) { //inopenId无效 return(notFound("您的邀请用户手机号无效!")); } //判断用户是否在APP端被邀请过 if (invite_bll.QueryExitByUsername(model.username)) { //用户在APP端被邀请过,邀请用户不再获得积分,只进行微信信息绑定,双方均不得积分。 if (bll.UpdateInsert1(model)) { return(ok(new { msg = "绑定成功" })); } return(notFound("绑定失败")); } //绑定只给邀请人积分,不给被邀请人积分 //邀请者记录 //条件 List <Wheres> whs = new List <Wheres>() { new Wheres("username", "=", model.authData.wechat.inopenId) }; _User user = bll.QuerySingleByWheres(whs); CreditsHistory history = new CreditsHistory(); history.objectId = guid.ToString(); history.createdAt = DateTime.Now; history.updatedAt = DateTime.Now; history.change = 30; history.credit = user.credit + 30; history.userId = user.objectId; //微信邀请好友 history.type = 3; if (bll.UpdateInsert(model, history)) { return(ok(new { msg = "绑定成功" })); } else { return(notFound("绑定失败")); } } //用户不存在 //微信注册操作 DateTime dt = DateTime.Now; model.objectId = guid.ToString(); //密码加盐保存 model.password = (model.password + model.objectId).Md5(); //初始化数据 model.nickname = "口袋爆料人"; model.credit = 40; model.overage = 0; model.sign_in = true; model.shake_times = 3; model.createdAt = dt; model.updatedAt = dt; string initPassword = "******"; model.transaction_password = (initPassword.Md5() + model.objectId).Md5(); CreditsHistory history2 = new CreditsHistory(); history2.objectId = guid.ToString(); history2.createdAt = dt; history2.updatedAt = dt; history2.change = 40; history2.credit = 40; history2.type = 4;//注册得积分 bool result = false; if (isNUll(model.authData.wechat.inopenId)) { //没有邀请人 result = bll.Insert(model, history2); } else { //有邀请人 //条件 List <Wheres> whs = new List <Wheres>() { new Wheres("username", "=", model.authData.wechat.inopenId) }; _User user = bll.QuerySingleByWheres(whs); CreditsHistory history1 = new CreditsHistory(); Guid guid1 = Guid.NewGuid(); history1.objectId = guid1.ToString(); history1.createdAt = dt; history1.updatedAt = dt; history1.type = 3;//邀请得积分 history1.change = 30; history1.credit = user.credit + 30; history1.userId = user.objectId; result = bll.Insert(model, history2, history1); } if (result) { return(ok(new { msg = "注册成功" })); } return(notFound("注册失败")); } catch (Exception e) { return(execept(e.Message)); } }