onePass.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <!--step2: 移动运营商需要判断referrer 请在验证后台添加根据需求添加对应的Referer&&Origin -->
  7. <meta content="always" name="referrer">
  8. <title>onepass demo演示</title>
  9. <style>
  10. body {
  11. margin: 50px 0;
  12. font-family: "PingFangSC-Regular", "Open Sans", Arial, "Hiragino Sans GB", "Microsoft YaHei", "STHeiti", "WenQuanYi Micro Hei", SimSun, sans-serif;
  13. text-align: center;
  14. }
  15. .inp {
  16. width: 278px;
  17. height: 40px;
  18. padding: 0 10px;
  19. font-size: 14px;
  20. border: 1px solid #ccc;
  21. border-radius: 2px;
  22. }
  23. .btn {
  24. display: inline-block;
  25. box-sizing: border-box;
  26. width: 120px;
  27. height: 40px;
  28. color: #666;
  29. font-size: 16px;
  30. line-height: 40px;
  31. background: white linear-gradient(180deg, #fff 0%, #f3f3f3 100%);
  32. border: 1px solid #ccc;
  33. border-radius: 2px;
  34. cursor: pointer;
  35. }
  36. .btn:hover {
  37. background: white linear-gradient(0deg, #fff 0%, #f3f3f3 100%);
  38. }
  39. #captcha {
  40. display: inline-block;
  41. width: 300px;
  42. }
  43. label {
  44. display: inline-block;
  45. width: 80px;
  46. text-align: right;
  47. vertical-align: top;
  48. }
  49. #wait {
  50. margin: 0;
  51. color: #666;
  52. text-align: left;
  53. }
  54. .txt_msg {
  55. width: 130px;
  56. }
  57. .btn_msg {
  58. width: 122px;
  59. height: 44px;
  60. margin: 0;
  61. color: #fff;
  62. font-size: 14px;
  63. background: #0bd8d0;
  64. border: solid 1px #ccc;
  65. border-radius: 2px;
  66. -webkit-appearance: none;
  67. }
  68. .btn_msg.disable {
  69. background: #ccc;
  70. }
  71. #btnStep1,
  72. #btnStep2 {
  73. color: #fff;
  74. background: #0bd8d0;
  75. }
  76. </style>
  77. </head>
  78. <body>
  79. <h1>注册</h1>
  80. <div>
  81. <div id="step1">
  82. <h5 style="color:red;">请先关闭WIFI</h5>
  83. <h5>demo 仅展示onepass H5 推荐逻辑</h5>
  84. <p>推荐根据script里代码的step步骤进行一步一步部署</p>
  85. <input id="phone" type="tel" class="inp" maxlength="11" placeholder="请输入手机号">
  86. </div>
  87. <br />
  88. <div id="step2" style="display: none;">
  89. <input id="txtmsg" type="tel" class="inp txt_msg" maxlength="6" placeholder="请输入短信验证码">
  90. <input type="button" class="btn_msg" id="btnGetMessage" value="获取验证码">
  91. <br />
  92. </div>
  93. <div id="btnStep1" class="btn">下一步</div>
  94. </div>
  95. <div id="step3" style="display: none;">
  96. <h3>注册成功</h3>
  97. </div>
  98. <!-- 手机查看日志 -->
  99. <!-- <script src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script>
  100. <script>
  101. var vConsole = new VConsole();
  102. </script> -->
  103. <!-- 本机验证本身不需要jquery 库,此处使用仅为了在demo中减少代码量 -->
  104. <script src="//apps.bdimg.com/libs/jquery/1.9.1/jquery.js"></script>
  105. <!-- stpe1: 引入JS -->
  106. <!-- 引入axios -->
  107. <!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script> -->
  108. <!-- 本地依赖 -->
  109. <script src="axios.min.js"></script>
  110. <!-- 引入gysdk-min-dev.js 注意路径-->
  111. <script src="gysdk-min.js"></script>
  112. <script type="text/javascript">
  113. const appid = "xOXlBEZffZ5cugKJMXMX13"
  114. const appKey = "aivIdLhtYC7zFEGccNInH5"
  115. const masterSecret = "fxS2KV2qfj8Eh1sJsyK8H2"
  116. var step1Div = $('#step1');
  117. var step2Div = $('#step2');
  118. var step3Div = $('#step3');
  119. var btnStep1 = $('#btnStep1');
  120. // 手机号码校验 ,用户可根据业务做不同判断
  121. function checkPhoneNumber() {
  122. var phoneEl = $('#phone');
  123. var phonenumber = phoneEl.val();
  124. if (!phonenumber) {
  125. alert('请输入手机号!');
  126. return false;
  127. }
  128. // 根据业务调整正则
  129. var phonereg = /^1\d{10}$/;
  130. var result = phonereg.test(phonenumber);
  131. if (!result) {
  132. alert('请输入正确的手机号');
  133. }
  134. return result;
  135. }
  136. //初始化个验SDK
  137. function initGy() {
  138. GyManager.setDebugMode(true)
  139. GyManager.init({
  140. app: "个验仅H5",
  141. appid: appid, timeout: 3000, onResult: function (res) {
  142. console.log("demo init ", res);
  143. if (res.success) {
  144. initResult = res;
  145. }
  146. }
  147. });
  148. }
  149. //保存初始化结果
  150. let initResult;
  151. // 可提前判断网络状态 决定是否初始化H5一键登录
  152. var nettype = GyManager.checkNetInfo();
  153. console.log("demo checkNetInfo", nettype);
  154. // 根据客户业务进行判断 网络判断返回 cellular、 wifi、 unknown
  155. if (nettype === 'wifi') {
  156. console.error("demo wifi状态无法一键验证")
  157. // 可选方案:
  158. // 1: 提示用户关闭wifi 进行体验
  159. // 2: 直接降级走其他验证形式
  160. } else {
  161. // stpe3: 初始化H5一键验证
  162. initGy()
  163. }
  164. // 点击登录进行校验流程
  165. $('#btnStep1').click(function (e) {
  166. // 以下为推荐逻辑 ,用户可根据业务进行更改
  167. // 手机号码检测 && 当前net状态
  168. var checkphone = checkPhoneNumber();
  169. // step4: 网络状态判断方法(非必选)
  170. var net = GyManager.checkNetInfo();
  171. if (checkphone && net !== 'wifi') {
  172. // 调用网关接口 // 参数为phone
  173. // step5: 网关接口调用
  174. GyManager.onePass({
  175. phone: $('#phone').val(),
  176. onGatewaySuccess: function (res) {
  177. console.log("onGatewaySuccess", res);
  178. //调用服务端校验接口
  179. },
  180. onGatewayFail: function (err) {
  181. console.error("onGatewayFail", err);
  182. }
  183. });
  184. } else {
  185. // 当前网络状态为wifi情况下直接调用短信
  186. }
  187. });
  188. </script>
  189. </body>
  190. </html>