您的位置 首页 php

apicloud写的简单用户登录源码分享

  1. <!DOCTYPE html>

  2. <html>

  3. <head>

  4. <meta charset=”utf-8″>

  5. <meta name=”viewport” content=”maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0″/>

  6. <meta name=”format-detection” content=”telephone=no,email=no,date=no,address=no”>

  7. <title>title</title>

  8. <link rel=”stylesheet” type=”text/css” href=”../css/api.css”/>

  9. <link rel=”stylesheet” type=”text/css” href=”../css/style.css” />

  10. <link rel=”stylesheet” type=”text/css” href=”../css/aui.2.0.css” />

  11. </head>

  12. <body>

  13. <div class=”aui-content aui-margin-b-15″>

  14. <ul class=”aui-list aui-form-list”>

  15. <li class=”aui-list-item”>

  16. <div class=”aui-list-item-inner”>

  17. <div class=”aui-list-item-label-icon”>

  18. <i class=”aui-iconfont aui-icon- mobile “></i>

  19. </div>

  20. <div class=”aui-list-item-input”>

  21. <input type=”text” placeholder=”手机号” id=”mobile”>

  22. </div>

  23. </div>

  24. </li>

  25. <li class=”aui-list-item”>

  26. <div class=”aui-list-item-inner”>

  27. <div class=”aui-list-item-label-icon”>

  28. <i class=”aui-iconfont aui-icon-lock”></i>

  29. </div>

  30. <div class=”aui-list-item-input”>

  31. <input type=”password” placeholder=”密码” id=”password”>

  32. </div>

  33. <div class=”aui-list-item-label-icon”>

  34. <i class=”aui-iconfont aui-icon-display”></i>

  35. </div>

  36. </div>

  37. </li>

  38. </ul>

  39. </div>

  40. <div class=”mui-content-padded” align=”center”>

  41. <button type=”button” class=”mui-btn mui-btn-blue” id=”login” onclick=”login();”>

  42. 登陆

  43. </button>

  44. <button type=”button” class=”mui-btn mui-btn-green” id=”reg” onclick=”user_reg();”>

  45. 注册

  46. </button>

  47. <button type=”button” class=”mui-btn mui-btn-green” id=”reset_password” onclick=”reset_password();”>

  48. 忘记密码

  49. </button>

  50. </div>

  51. </body>

  52. < script type=”text/javascript” src=”../script/api.js”></script>

  53. <script type=”text/javascript”>

  54. function login() {

  55. api.ajax({

  56. url : ‘

  57. method : ‘post’,

  58. data : {

  59. values : {

  60. mobile : document.getElementById(“mobile”).value,

  61. password : document.getElementById(“password”).value,

  62. uuid : api.deviceId

  63. }

  64. }

  65. }, function(data) {

  66. if (data) {

  67. if (data.code == 200) {

  68. //登录成功

  69. alert(‘登录成功’);

  70. $api.setStorage(“token”, data.token);

  71. $api.setStorage(‘mobile’, data.data.phone);

  72. $api.setStorage(‘alipay’, data.data.alipay);

  73. $api.setStorage(‘weixin’, data.data.weixin);

  74. $api.setStorage(‘realname’, data.data.realname);

  75. $api.setStorage(‘address’, data.data.address);

  76. $api.setStorage(‘caiwu’, data.data.caiwu);

  77. $api.setStorage(‘ grade ‘, data.data.grade);

  78. $api.setStorage(‘is_buy’, data.data.is_buy);

  79. $api.setStorage(‘is_inquiry’, data.data.is_inquiry);

  80. $api.setStorage(‘is_addproduct’, data.data.is_addproduct);

  81. $api.setStorage(‘is_checkout’, data.data.is_checkout);

  82. $api.setStorage(‘is_stock’, data.data.is_stock);

  83. $api.setStorage(‘is_cart’, data.data.is_cart);

  84. if (data.data.pid > 0) {

  85. $api.setStorage(‘is_pid’, 2);

  86. } else {

  87. $api.setStorage(‘is_pid’, 1);

  88. }

  89. create_db();

  90. // $api.setStorage(‘userid’, data.data.id);

  91. if ($api.getStorage(“from”) == ‘cart’) {

  92. api.closeToWin({

  93. name : ‘cart_subcart’

  94. });

  95. api.execScript({

  96. name : ‘cart_subcart’,

  97. frameName : ‘cart_subcart’,

  98. script : ‘winreload();’

  99. });

  100. } else if ($api.getStorage(“from”) == ‘inquiry’) {

  101. api.closeToWin({

  102. name : ‘inquiry’

  103. });

  104. api.execScript({

  105. name : ‘inquiry’,

  106. frameName : ‘inquiry_form’,

  107. script : ‘winreload();’

  108. });

  109. } else {

  110. api.openWin({

  111. name : ‘personer_index’,

  112. url : ‘./a_headbackindex.html’,

  113. pageParam : {

  114. title : ‘个人中心’,

  115. url : ‘personer_index’

  116. }

  117. });

  118. }

  119. } else if (data.code == 402) {

  120. //登录失败

  121. alert(‘密码错误’);

  122. } else if (data.code == 403) {

  123. //登录失败

  124. alert(‘账号错误’);

  125. }

  126. } else {

  127. api.alert(‘111’);

  128. }

  129. });

  130. }

  131. //用户注册

  132. function user_reg() {

  133. api.openWin({

  134. name : ‘personer_reg’,

  135. url : ‘./a_headbackindex.html’,

  136. pageParam : {

  137. title : ‘注册’,

  138. url : ‘personer_reg’

  139. }

  140. });

  141. }

  142. //重置密码

  143. function reset_password() {

  144. api.openWin({

  145. name : ‘personer_resetpassword’,

  146. url : ‘./a_headbackindex.html’,

  147. pageParam : {

  148. title : ‘重置密码’,

  149. url : ‘personer_resetpassword’

  150. }

  151. });

  152. }

  153. var db;

  154. apiready = function() {

  155. db = api.require(‘db’);

  156. };

  157. //创建数据库

  158. function create_db() {

  159. db.openDatabase({

  160. name : ‘ghuog_db’ + $api.getStorage(‘mobile’)

  161. }, function(ret, err) {

  162. if (ret.status) {

  163. db.execute sql ({

  164. name : ‘ghuog_db’ + $api.getStorage(‘mobile’),

  165. sql : “create table T_Product(id integer primary key autoincrement,BarCode varchar(255) unique,ProName varchar(255),Num int(11),AddTime datetime,CostPrice float,MarketPrice float,ProPosition varchar(25),Status tinyint(1),supId int(10),ProSpec varchar(255),ProCat int(10))”

  166. }, function(ret, err) {

  167. if (ret.status) {

  168. alert(‘商品表创建成功’);

  169. } else {

  170. }

  171. });

  172. db.executeSql({

  173. name : ‘ghuog_db’ + $api.getStorage(‘mobile’),

  174. sql : “create table T_Stock(id integer primary key autoincrement,BarCode varchar(255),Num int(11),StockTime datetime,Note varchar(255),Status tinyint(1))”

  175. //sql : “INSERT INTO Product(BarCode,ProName,Num,CostPrice,MarketPrice,ProPosition)VALUES(‘123456789′,’测试商品’,’12’,’25’,’38’,’A1′)”

  176. }, function(ret, err) {

  177. if (ret.status) {

  178. alert(‘库存表创建成功’);

  179. } else {

  180. }

  181. });

  182. db.executeSql({

  183. name : ‘ghuog_db’ + $api.getStorage(‘mobile’),

  184. sql : “create table T_CheckOut(id integer primary key autoincrement,ProName varchar(255),MarketPrice float,BarCode varchar(255),Num int(11),CheckTime datetime,OrderNum varchar(255),SubTotal float,Total float,Status tinyint(1))”

  185. //sql : “INSERT INTO Product(BarCode,ProName,Num,CostPrice,MarketPrice,ProPosition)VALUES(‘123456789′,’测试商品’,’12’,’25’,’38’,’A1′)”

  186. }, function(ret, err) {

  187. if (ret.status) {

  188. alert(‘出库表创建成功’);

  189. } else {

  190. }

  191. });

  192. db.executeSql({

  193. name : ‘ghuog_db’ + $api.getStorage(‘mobile’),

  194. sql : “create table T_Supplier(id integer primary key autoincrement,pid integer not null,supid integer unique,SupplierName varchar(255),SupplierTel varchar(60),SupplierContact varchar(25),Status integer)”

  195. //sql : “INSERT INTO Product(BarCode,ProName,Num,CostPrice,MarketPrice,ProPosition)VALUES(‘123456789′,’测试商品’,’12’,’25’,’38’,’A1′)”

  196. }, function(ret, err) {

  197. if (ret.status) {

  198. alert(‘供应商表创建成功’);

  199. } else {

  200. }

  201. });

  202. //供应商分类表

  203. db.executeSql({

  204. name : ‘ghuog_db’ + $api.getStorage(‘mobile’),

  205. sql : “create table T_SupplierCat(id integer primary key autoincrement,pid integer,catid integer UNIQUE,SupplierCatName varchar(255))”

  206. }, function(ret, err) {

  207. if (ret.status) {

  208. alert(‘供应商分类表创建成功’);

  209. } else {

  210. }

  211. });

  212. //商品分类表

  213. db.executeSql({

  214. name : ‘ghuog_db’ + $api.getStorage(‘mobile’),

  215. sql : “create table T_ProductCat(id integer primary key autoincrement,pid integer,catid integer UNIQUE,ProductCatName varchar(255))”

  216. }, function(ret, err) {

  217. if (ret.status) {

  218. alert(‘商品分类表创建成功’);

  219. } else {

  220. }

  221. });

  222. //商品退货表

  223. db.executeSql({

  224. name : ‘ghuog_db’ + $api.getStorage(‘mobile’),

  225. sql : “create table T_ProductReturn(id integer primary key autoincrement,barcode varchar(60),num integer,is_sell tinyint,time datetime,note varchar(255),reason varchar(255),status tinyint)”

  226. }, function(ret, err) {

  227. if (ret.status) {

  228. alert(‘商品退货表创建成功’);

  229. } else {

  230. }

  231. });

  232. } else {

  233. }

  234. });

  235. }

  236. </script>

  237. </html>

复制代码

接口代码

  1. public function login()

  2. {

  3. $data[‘phone’] = Request ::instance()->post(‘mobile’);

  4. // $data[‘password’] = Request::instance()->post(‘password’);

  5. $uid = Db::table(‘member’)->where(‘phone’, $data[‘phone’])->value(‘pid’);

  6. $row = Db::table(‘member’)->where($data)->find();

  7. if ($row) {

  8. if ($row[‘password’] == md5(Request::instance()->post(‘password’))) {

  9. $str = Db::table(‘member’)->where(‘phone’, $data[‘phone’])->find();

  10. $insert[‘appsecret’] = md5($str[‘secret’] . $str[‘appid’] . time());

  11. $insert[‘uid’] = $str[‘id’];

  12. $insert[‘time’] = time();

  13. $insert[‘last_uuid’] = Request::instance()->post(‘uuid’);

  14. if (!$uid) {

  15. $uid3 = $str[‘id’];

  16. } else {

  17. $uid3 = $uid;

  18. }

  19. if (Db::table(‘appsecret’)->insert($insert)) {

  20. $res[‘code’] = 200;

  21. $res[‘message’] = ‘登录成功’;

  22. $res[‘token’] = $insert[‘appsecret’];

  23. $res[‘data’] = Db::table(‘member’)->where(‘phone’, $data[‘phone’])->find();

  24. $res[‘data’][‘grade’] = Db::table(‘member’)->where(‘id’, $uid3)->value(‘grade’);

  25. }

  26. } else {

  27. $res[‘code’] = 402;

  28. $res[‘message’] = ‘密码错误’;

  29. }

  30. } else {

  31. $res[‘code’] = 403;

  32. $res[‘message’] = ‘账号错误’;

  33. }

  34. echo json_encode($res);

  35. }

333333333333333.png (35.47 KB, 下载次数: 4)

下载附件

2016-11-30 17:58 上传

用户登录,调用接口

文章来源:智云一二三科技

文章标题:apicloud写的简单用户登录源码分享

文章地址:https://www.zhihuclub.com/153018.shtml

关于作者: 智云科技

热门文章

网站地图