Discuz iOS应用开发 - bigApp iOS源码分析 - 新用户注册流程

先来看新用户的注册流程,注册界面如下

点击注册事实上是以Post方式提交了一个Http请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 NSDictionary *dic = @{@"regsubmit":@"yes",@"un":avoidNullStr(username),@"pd":avoidNullStr(password),@"pd2":avoidNullStr(password2),@"em":avoidNullStr(email)};
[[ClanNetAPI sharedJsonClient] requestJsonDataWithPath:[NSString stringWithFormat:@"%@?version=%@&module=newuser&iyzmobile=1&inajax=1",_kurl_base_path,ClanVersion] withParams:dic withMethodType:Post andBlock:^(id data, NSError *error) {
if (error) {
block(error);
} else {
NSDictionary *dic = data[@"Message"];
if ([dic[@"messageval"] isEqualToString:@"register_succeed"]) {
//注册成功 登录
[ClanNetAPI saveCookieData];
[[NSUserDefaults standardUserDefaults] setObject:username forKey:@"kLASTUSERNAME"];

UserModel *user = [UserModel currentUserInfo];
[user setValueWithObject:[UserModel objectWithKeyValues:data]];
//设置登录成功
user.logined = YES;
[UserModel saveToLocal];
if (fid) {
[self request_checkPostWithFid:fid];
}
}
block(data);
}
}];

分析下这个Http请求

  • baseUrl: http://localhost/inspirelifebbs/
    无疑这个是论坛网站的URL
  • basePath: api/mobile/iyz_index.php?version=4&module=newuser&iyzmobile=1&inajax=1
    api/mobile/iyz_index.php?为BigApp插件定义的mobile API。可以在api/mobile/找到源码。大概就是去找../../source/plugin/bigapp/bigapp.php中定义的module
    1
    2
    3
    4
    5
    6
    7
    $plugin = !empty($_GET['oem']) ? 'mobileoem' : 'mobile';
    $file = 'mobile.php';
    if(isset($_GET['iyzmobile']) && $_GET['iyzmobile']){
    $plugin = 'bigapp';
    $file = 'bigapp.php';
    }
    $dir = '../../source/plugin/'.$plugin.'/';

iyzmobile=1我猜大概就在这里需要用到。而inajax=1这个参数就不太清楚它的用意。

然后再看source/plugin/bigapp/bigapp.php的源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$modules = array('forumnav', 'forumnav2', 'editpost', 'deletepm', 'deletepl', 'mythread2', 'delfav', 'login3body', 'newuser', 
'captcha', 'checknewpm', 'myhome','myportal','secquestion', 'checkpost', 'forumupload', 'postsupport', 'search', 'searchuser',
'searchforum', 'threadrecommend2', 'newfriend', 'findfriend', 'addfriend', 'auditfriend', 'removefriend','plugcfg', 'report',
'platform_login', 'thrdtype', 'smilies', 'checkin', 'indexthread','favarticle','myfavarticle', 'indexcfg','contentthread', 'getaksk','modpass','viewinfo', 'activityclient', 'activityapplylist', 'viewratings','rate','ratepost','comment','commentmore','commentpost','commentnotice', 'removepost', 'removethread');

$defaultversions = array(
'forumnav' => 4,
'editpost' => 4,
'forumnav2' => 4,
'deletepm' => 4,
'deletepl' => 4,
'mythread2' => 4,
'delfav' => 4,
'login3body' => 4,
'newuser' => 4,
'captcha' => 4,
'checknewpm' => 4,
'checkpost' => 4,
'forumupload' => 4,
'postsupport' => 4,
'search' => 4,
'searchuser' => 4,
'searchforum' => 4,
'threadrecommend2' => 4,
'plugcfg' => 4,
'thrdtype' => 4,
'getaksk' => 4,
'getarticle' => 4,
'activityclient' => 4,
'activityapplylist' => 4,
'viewratings' => 4,
'rate' => 4,
'ratepost' => 4,
'removepost' => 4,
'removethread' => 4,
'newfriend' => 4,
'findfriend' => 4,
'addfriend' => 4,
'auditfriend' => 4,
'removefriend' => 4,
'report' => 4,
'platform_login' => 4,
'smilies' => 4,
'checkin' => 4,
'indexthread' => 4,
'myhome' => 4,
'testtids' => 4,
'modpass' => 4,
);

可以看到他定义了各个模块以及模块的版本,所以version=4&module=newuser这两个参数应该就是这边需要的

例如apifile的定义

1
$apifile = dirname(__FILE__) . '/api/'.$_GET['iyzversion'].'/'.$_GET['module'].'.php';

  • params:
    参数以字典的形式定义,在模块中会读取。根据上述定义,我们可以在source/plugin/bigapp/api/1/下找到newuser.php
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    if(isset($_REQUEST['un']) && !empty($_REQUEST['un'])){
    $userName = $_REQUEST['un'];
    }
    if(isset($_REQUEST['pd']) && !empty($_REQUEST['pd'])){
    $password = $_REQUEST['pd'];
    if(!isset($_REQUEST['pd2']) || $_REQUEST['pd2'] != $_REQUEST['pd']){
    echo BIGAPPJSON::encode(array('error_code' => 1, 'error_msg' => lang('plugin/bigapp', 'password_not_equal'),
    'Variables' => array('auth' => null), 'Message' => array('messageval' => 'for comaptible',
    'messagestr' => lang('plugin/bigapp', 'password_not_equal'))));
    die(0);
    }
    }
    if(isset($_REQUEST['em']) && !empty($_REQUEST['em'])){
    $email = strtolower($_REQUEST['em']);
    }

可以看到_REQUEST读取了em,pd,pd2,un等参数,所以这就是参数字典的来源。暂时不清楚regsubmit参数的作用。
{
em = “Test@hotmail.com”;
pd = test;
pd2 = test;
regsubmit = yes;
un = Test;
}

  • httpType: Post
  • returnValue:

在密码等都设置正确之后,最后的结果是返回“手机端暂不支持用户注册”

查看出错的这段定义,意味着!isset($_G[‘setting’][‘mobile’][‘mobileregister’]) 没有被定义或者为NO,那么这个_G[‘setting’]是在哪里定义的?

1
2
3
4
5
if(!isset($_G['setting']['mobile']['mobileregister']) || !$_G['setting']['mobile']['mobileregister']){
echo BIGAPPJSON::encode(array('error_code' => 7, 'error_msg' => lang('plugin/bigapp', 'forbid_mobreg'),
'Variables' => array('auth' => null), 'Message' => array('messageval' => 'for comaptible', 'messagestr' => lang('plugin/bigapp', 'forbid_mobreg'))));
die(0);
}

从插件的配置页面可以得到的提示是该功能需要站长认证!

临时的解决方案:
把这段检查的代码注释掉,同样把error_code = 8的那段代码注释掉,最终可以注册成功

工时:

  1. 0.5 day