增加发送短信的图形验证码功能

This commit is contained in:
zhl 2019-02-26 21:46:37 +08:00
parent e736b930d1
commit 20886ecf78
11 changed files with 3464 additions and 60 deletions

View File

@ -41,8 +41,8 @@
},
"_scale": {
"__type__": "cc.Vec3",
"x": 0.4469148552288877,
"y": 0.4469148552288877,
"x": 0.11809926614295294,
"y": 0.11809926614295294,
"z": 1
},
"_quat": {
@ -646,6 +646,9 @@
"inviteMenuPrefab": {
"__uuid__": "bdf9cd55-9cf3-4bf8-b902-2431701b3d6c"
},
"infoMenuPrefab2": {
"__uuid__": "14e28457-5820-4f5b-a685-e9a9083b336c"
},
"rulePrefab": {
"__uuid__": "de027dd7-a186-4797-b332-2f6e2603d165"
},
@ -656,6 +659,7 @@
"__uuid__": "6c21a659-0cc4-49e6-a4b6-9697e946aaa1"
},
"topMenu": null,
"partsY": [],
"_id": "caqu3+UstJ+6Bc+xrIMgmV"
},
{

View File

@ -26,21 +26,21 @@
"__id__": 10
},
{
"__id__": 57
"__id__": 58
}
],
"_active": true,
"_level": 1,
"_components": [
{
"__id__": 68
"__id__": 69
},
{
"__id__": 69
"__id__": 70
}
],
"_prefab": {
"__id__": 70
"__id__": 71
},
"_opacity": 255,
"_color": {
@ -346,18 +346,18 @@
"__id__": 11
},
{
"__id__": 47
"__id__": 48
}
],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 55
"__id__": 56
}
],
"_prefab": {
"__id__": 56
"__id__": 57
},
"_opacity": 255,
"_color": {
@ -432,11 +432,11 @@
"_level": 4,
"_components": [
{
"__id__": 45
"__id__": 46
}
],
"_prefab": {
"__id__": 46
"__id__": 47
},
"_opacity": 255,
"_color": {
@ -833,7 +833,7 @@
"_useOriginalSize": true,
"_string": "",
"_N$string": "",
"_fontSize": 20,
"_fontSize": 30,
"_lineHeight": 40,
"_enableWrapText": false,
"_N$file": null,
@ -973,10 +973,10 @@
"_N$backgroundImage": {
"__uuid__": "ed4c60fd-a3c0-4565-a0e9-9a7d82b14c7a"
},
"_N$returnType": 0,
"_N$returnType": 2,
"_N$inputFlag": 5,
"_N$inputMode": 6,
"_N$fontSize": 20,
"_N$inputMode": 3,
"_N$fontSize": 30,
"_N$lineHeight": 40,
"_N$fontColor": {
"__type__": "cc.Color",
@ -994,7 +994,7 @@
"b": 187,
"a": 255
},
"_N$maxLength": 8,
"_N$maxLength": 11,
"_N$stayOnTop": false,
"_id": ""
},
@ -1359,7 +1359,7 @@
"_useOriginalSize": true,
"_string": "",
"_N$string": "",
"_fontSize": 20,
"_fontSize": 30,
"_lineHeight": 40,
"_enableWrapText": false,
"_N$file": null,
@ -1501,8 +1501,8 @@
},
"_N$returnType": 0,
"_N$inputFlag": 5,
"_N$inputMode": 6,
"_N$fontSize": 20,
"_N$inputMode": 2,
"_N$fontSize": 30,
"_N$lineHeight": 40,
"_N$fontColor": {
"__type__": "cc.Color",
@ -1520,7 +1520,7 @@
"b": 187,
"a": 255
},
"_N$maxLength": 8,
"_N$maxLength": 6,
"_N$stayOnTop": false,
"_id": ""
},
@ -1548,10 +1548,13 @@
"_components": [
{
"__id__": 43
},
{
"__id__": 44
}
],
"_prefab": {
"__id__": 44
"__id__": 45
},
"_opacity": 255,
"_color": {
@ -1626,6 +1629,59 @@
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 42
},
"_enabled": true,
"transition": 0,
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 214,
"g": 214,
"b": 214,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 42
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
@ -1685,21 +1741,21 @@
},
"_children": [
{
"__id__": 48
"__id__": 49
}
],
"_active": true,
"_level": 4,
"_components": [
{
"__id__": 52
"__id__": 53
},
{
"__id__": 53
"__id__": 54
}
],
"_prefab": {
"__id__": 54
"__id__": 55
},
"_opacity": 255,
"_color": {
@ -1751,21 +1807,21 @@
"_name": "New Label",
"_objFlags": 0,
"_parent": {
"__id__": 47
"__id__": 48
},
"_children": [],
"_active": true,
"_level": 5,
"_components": [
{
"__id__": 49
"__id__": 50
},
{
"__id__": 50
"__id__": 51
}
],
"_prefab": {
"__id__": 51
"__id__": 52
},
"_opacity": 255,
"_color": {
@ -1817,7 +1873,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 48
"__id__": 49
},
"_enabled": true,
"_srcBlendFactor": 1,
@ -1842,7 +1898,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 48
"__id__": 49
},
"_enabled": true,
"_color": {
@ -1871,7 +1927,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 47
"__id__": 48
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -1899,7 +1955,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 47
"__id__": 48
},
"_enabled": true,
"transition": 0,
@ -1943,7 +1999,7 @@
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 47
"__id__": 48
},
"_id": ""
},
@ -2006,21 +2062,21 @@
},
"_children": [
{
"__id__": 58
"__id__": 59
},
{
"__id__": 62
"__id__": 63
}
],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 66
"__id__": 67
}
],
"_prefab": {
"__id__": 67
"__id__": 68
},
"_opacity": 255,
"_color": {
@ -2072,21 +2128,21 @@
"_name": "menu_close_btn",
"_objFlags": 0,
"_parent": {
"__id__": 57
"__id__": 58
},
"_children": [],
"_active": true,
"_level": 4,
"_components": [
{
"__id__": 59
"__id__": 60
},
{
"__id__": 60
"__id__": 61
}
],
"_prefab": {
"__id__": 61
"__id__": 62
},
"_opacity": 255,
"_color": {
@ -2138,7 +2194,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 58
"__id__": 59
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -2166,7 +2222,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 58
"__id__": 59
},
"_enabled": true,
"transition": 0,
@ -2210,7 +2266,7 @@
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 58
"__id__": 59
},
"_id": ""
},
@ -2230,21 +2286,21 @@
"_name": "New Label",
"_objFlags": 0,
"_parent": {
"__id__": 57
"__id__": 58
},
"_children": [],
"_active": true,
"_level": 4,
"_components": [
{
"__id__": 63
"__id__": 64
},
{
"__id__": 64
"__id__": 65
}
],
"_prefab": {
"__id__": 65
"__id__": 66
},
"_opacity": 255,
"_color": {
@ -2296,7 +2352,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 62
"__id__": 63
},
"_enabled": true,
"_srcBlendFactor": 1,
@ -2321,7 +2377,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 62
"__id__": 63
},
"_enabled": true,
"_color": {
@ -2350,7 +2406,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 57
"__id__": 58
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -2420,14 +2476,23 @@
},
"_enabled": true,
"closeBtn": {
"__id__": 58
"__id__": 59
},
"submitBtn": {
"__id__": 47
"__id__": 48
},
"captchaBtn": {
"__id__": 42
},
"resultPrefab": {
"__uuid__": "50fc505c-5051-4781-84b8-6bdf8254ed17"
},
"mobileInput": {
"__id__": 25
},
"captchaInput": {
"__id__": 40
},
"_id": ""
},
{

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "14e28457-5820-4f5b-a685-e9a9083b336c",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"subMetas": {}
}

View File

@ -1,3 +1,5 @@
let webapi = require('./utils/webapi');
let stringUtil = require('./utils/string.util');
cc.Class({
extends: cc.Component,
@ -10,9 +12,29 @@ cc.Class({
default: null,
type: cc.Node
},
captchaBtn: {
default: null,
type: cc.Node
},
resultPrefab: {
default: null,
type: cc.Prefab
},
mobileInput: {
default: null,
type: cc.EditBox
},
captchaInput: {
default: null,
type: cc.EditBox
},
codeInput: {
default: null,
type: cc.EditBox
},
codeImg: {
default: null,
type: cc.Sprite
}
},
@ -20,11 +42,32 @@ cc.Class({
onLoad () {
let self = this;
if (this.top.needCode) {
this.showCaptchaInput();
this.codeImg.node.on('click', function () {
self.showCaptchaInput();
})
}
this.closeBtn.on('click', function () {
self.node.removeFromParent(true);
});
this.submitBtn.on('click', function () {
self.showResultView();
let mobile = self.mobileInput.string;
});
this.captchaBtn.on('click', function () {
console.log(self.mobileInput.string);
let mobile = self.mobileInput.string;
if (!stringUtil.checkMobile(mobile)) {
alert('请输入有效的手机号码。');
return false;
}
webapi.sendSms(mobile)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
})
})
},
@ -35,5 +78,19 @@ cc.Class({
let result = cc.instantiate(this.resultPrefab);
this.top.node.addChild(result, 11);
this.node.removeFromParent(true);
},
showCaptchaInput() {
let self = this;
cc.loader.load({
url: webapi.captchaUrl()+'?'+new Date(),
type: 'jpg'
}, function (err, texture) {
if (err) {
console.log('load avatar error === ', err);
return;
}
self.codeImg.spriteFrame = new cc.SpriteFrame(texture);
});
}
});

View File

@ -36,6 +36,10 @@ cc.Class({
default: null,
type: cc.Prefab
},
infoMenuPrefab2: {
default: null,
type: cc.Prefab
},
rulePrefab: {
default: null,
type: cc.Prefab
@ -52,14 +56,15 @@ cc.Class({
default: null,
type: cc.Node
},
partsY: []
partsY: [],
needCode: true
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
let self = this;
http.get('http://192.168.100.228:7456/res/import/4d/4d364e42-855d-4e28-abe4-0221d8b6c47b.json', {} )
http.get('http://192.168.100.228/activity/api/index', {} )
.then(res => {
console.log(res);
})
@ -124,7 +129,12 @@ cc.Class({
this.topMenu.active = false;
},
showInfoMenu() {
let infoMenu = cc.instantiate(this.infoMenuPrefab);
let infoMenu;
if (this.needCode) {
infoMenu = cc.instantiate(this.infoMenuPrefab2);
} else {
infoMenu = cc.instantiate(this.infoMenuPrefab);
}
infoMenu.getComponent('infoMenu').top = this;
this.node.addChild(infoMenu, 11);
},

View File

@ -7,8 +7,14 @@ const get = (url, header) => {
const post = (url, data, header) => {
header = header || {};
header['Content-Type'] = 'application/json';
return Ajax(url, 'POST', data, header)
let formStr = '';
let i = 0;
for(let key in data) {
if (i ++ > 0) formStr += '&';
formStr += (key + '=' + data[key]);
}
header['Content-Type'] = 'application/x-www-form-urlencoded';
return Ajax(url, 'POST', formStr, header)
};
const Ajax = (url, method, data, header) => {

View File

@ -0,0 +1,11 @@
export default {
checkMobile(mobile) {
return /^1\d{10}$/.test(mobile);
},
checkAuthCode(code) {
return /^\d{6}$/.test(code);
},
checkCaptcheCode(code) {
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "d71687dd-e39a-4e7f-97e4-6fc499fea404",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -0,0 +1,17 @@
var http = require('./http');
const baseUrl = 'http://192.168.100.228';
export default {
sendSms: (mobile, captcha) => {
let data = {mobile: mobile};
if (captcha) {
data['captcha'] = captcha;
}
let url = baseUrl + '/activity/api/send_sms';
return http.post(url, data);
},
captchaUrl: () => {
return baseUrl + '/captcha/ch/login'
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "c750bf25-4ad4-4de7-b570-efcb5f8a7f6f",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}