Skip to content

Commit

Permalink
修复注册验证bug,更新readme
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyanan committed Sep 18, 2017
1 parent 7522af7 commit 9f0701f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 128 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ JChat 同时具备好友模式和无好友模式:
* 无好友模式:无需将对方加为好友,通过搜索对方的用户名可直接发起聊天。
* 好友模式:可申请将对方加为好友,对方会收到好友验证,验证通过则互为好友关系。

目前已覆盖 Android 和 [iOS](https://github.com/jpush/jchat-swift) 平台,之后将提供 web 版本,开发者可参照 JChat 快速打造自己的 APP,提高开发效率。
目前已覆盖 Android 和 [iOS](https://github.com/jpush/jchat-swift) 平台,之后将提供 web 版本,开发者可参照 JChat 快速打造自己的 APP,提高开发效率。

* 更换 AppKey
- 在 AndroidManifest.xml 文件中把 JChat 的 AppKey 替换成自己项目的 AppKey
* 更换包名
- 在 build.gradle 把 defaultConfig 节点下的 applicationId 替换成自己项目的包名

![jiguang](./image/6.gif)
![jiguang](./image/9.gif)
Expand Down Expand Up @@ -50,6 +55,10 @@ JChat 同时具备好友模式和无好友模式:
- Picasso —— 加载、显示、缓存图片
- 百度地图

### 特别说明
* JChat 不支持eclipse
* JChat 是一个单独的完整项目,不能作为module添加到其他项目中

### 相关文档

* [JMessage Android 集成指南](https://docs.jiguang.cn/jmessage/client/jmessage_android_guide/)
Expand Down
2 changes: 1 addition & 1 deletion chatapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 18
targetSdkVersion 23
versionCode 61
versionName "2.1.0"
versionName "2.1.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
7 changes: 6 additions & 1 deletion chatapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,26 @@

<activity
android:name=".activity.WelcomeActivity"
android:screenOrientation="portrait"
android:theme="@style/WelcomeStyle">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activity.LoginActivity"/>
<activity android:name=".activity.LoginActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppBaseTheme"
android:windowSoftInputMode="adjustPan|stateHidden"/>
<activity android:name=".activity.BaseActivity"/>
<activity
android:name=".activity.FinishRegisterActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible"
android:theme="@style/BaseThemes"/>
<activity
android:name=".activity.ResetPasswordActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
Expand All @@ -27,7 +26,6 @@
import jiguang.chat.R;
import jiguang.chat.application.JGApplication;
import jiguang.chat.database.UserEntry;
import jiguang.chat.utils.HandleResponseCode;
import jiguang.chat.utils.SharePreferenceManager;
import jiguang.chat.utils.ThreadUtil;
import jiguang.chat.utils.photochoose.ChoosePhoto;
Expand Down Expand Up @@ -102,72 +100,59 @@ public void onClick(View view) {

final String userId = SharePreferenceManager.getRegistrName();
final String password = SharePreferenceManager.getRegistrPass();
JMessageClient.register(userId, password, new BasicCallback() {
JMessageClient.login(userId, password, new BasicCallback() {
@Override
public void gotResult(int responseCode, String responseMessage) {
if (responseCode == 0) {
SharePreferenceManager.setRegisterUsername(userId);
JMessageClient.login(userId, password, new BasicCallback() {
JGApplication.registerOrLogin = 1;
String username = JMessageClient.getMyInfo().getUserName();
String appKey = JMessageClient.getMyInfo().getAppKey();
UserEntry user = UserEntry.getUser(username, appKey);
if (null == user) {
user = new UserEntry(username, appKey);
user.save();
}

String nickName = mNickNameEt.getText().toString();

UserInfo myUserInfo = JMessageClient.getMyInfo();
if (myUserInfo != null) {
myUserInfo.setNickname(nickName);
}
//注册时候更新昵称
JMessageClient.updateMyInfo(UserInfo.Field.nickname, myUserInfo, new BasicCallback() {
@Override
public void gotResult(int responseCode, String responseMessage) {
if (responseCode == 0) {
JGApplication.registerOrLogin = 1;
String username = JMessageClient.getMyInfo().getUserName();
String appKey = JMessageClient.getMyInfo().getAppKey();
UserEntry user = UserEntry.getUser(username, appKey);
if (null == user) {
user = new UserEntry(username, appKey);
user.save();
}

String nickName = mNickNameEt.getText().toString();

UserInfo myUserInfo = JMessageClient.getMyInfo();
if (myUserInfo != null) {
myUserInfo.setNickname(nickName);
}
//注册时候更新昵称
JMessageClient.updateMyInfo(UserInfo.Field.nickname, myUserInfo, new BasicCallback() {
public void gotResult(final int status, String desc) {
//更新跳转标志
SharePreferenceManager.setCachedFixProfileFlag(false);
mDialog.dismiss();
if (status == 0) {
goToActivity(FinishRegisterActivity.this, MainActivity.class);
}
}
});
//注册时更新头像
final String avatarPath = SharePreferenceManager.getRegisterAvatarPath();
if (avatarPath != null) {
ThreadUtil.runInThread(new Runnable() {
@Override
public void run() {
JMessageClient.updateUserAvatar(new File(avatarPath), new BasicCallback() {
@Override
public void gotResult(final int status, String desc) {
//更新跳转标志
SharePreferenceManager.setCachedFixProfileFlag(false);
mDialog.dismiss();
if (status == 0) {
goToActivity(FinishRegisterActivity.this, MainActivity.class);
public void gotResult(int responseCode, String responseMessage) {
if (responseCode == 0) {
SharePreferenceManager.setCachedAvatarPath(avatarPath);
}
}
});
//注册时更新头像
final String avatarPath = SharePreferenceManager.getRegisterAvatarPath();
if (avatarPath != null) {
ThreadUtil.runInThread(new Runnable() {
@Override
public void run() {
JMessageClient.updateUserAvatar(new File(avatarPath), new BasicCallback() {
@Override
public void gotResult(int responseCode, String responseMessage) {
if (responseCode == 0) {
SharePreferenceManager.setCachedAvatarPath(avatarPath);
}
}
});
}
});
} else {
SharePreferenceManager.setCachedAvatarPath(null);
}
}
}
});
} else {
HandleResponseCode.onHandle(mContext, responseCode, false);
mDialog.dismiss();
});
} else {
SharePreferenceManager.setCachedAvatarPath(null);
}
}
}
});

break;
}
}
};
Expand Down Expand Up @@ -206,11 +191,11 @@ public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
@Override
public void onTextChanged(CharSequence cs, int start, int before,
int count) {
if (!TextUtils.isEmpty(mNickNameEt.getText().toString())) {
mFinishBtn.setEnabled(true);
} else {
mFinishBtn.setEnabled(false);
}
// if (!TextUtils.isEmpty(mNickNameEt.getText().toString())) {
// mFinishBtn.setEnabled(true);
// } else {
// mFinishBtn.setEnabled(false);
// }
}
}
}
69 changes: 7 additions & 62 deletions chatapp/src/main/java/jiguang/chat/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import android.text.TextUtils;
import android.view.View;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -24,6 +19,7 @@
import jiguang.chat.application.JGApplication;
import jiguang.chat.database.UserEntry;
import jiguang.chat.utils.DialogCreator;
import jiguang.chat.utils.HandleResponseCode;
import jiguang.chat.utils.SharePreferenceManager;
import jiguang.chat.utils.ToastUtil;

Expand Down Expand Up @@ -144,27 +140,19 @@ public void gotResult(int responseCode, String responseMessage) {
});
//注册
} else {
final String uri = "https://api.im.jpush.cn/v1" + "/users/" + userId;
new Thread(new Runnable() {
JMessageClient.register(userId, password, new BasicCallback() {
@Override
public void run() {
String httpGet = executeHttpPost(uri);
if (httpGet == null) {
public void gotResult(int i, String s) {
if (i == 0) {
SharePreferenceManager.setRegisterName(userId);
SharePreferenceManager.setRegistePass(password);
mContext.startActivity(new Intent(mContext, FinishRegisterActivity.class));
ToastUtil.shortToast(mContext, "注册成功");
} else {
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
ToastUtil.shortToast(mContext, "该用户已经存在");
}
});
HandleResponseCode.onHandle(mContext, i, false);
}

}
}).start();

});
}
break;
case R.id.login_register:
Expand All @@ -185,47 +173,4 @@ public void run() {
break;
}
}

public String executeHttpPost(final String uid) {
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try {
//GET请求直接在链接后面拼上请求参数
URL url = new URL(uid);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
//Get请求不需要DoOutPut
conn.setDoOutput(false);
conn.setDoInput(true);
//设置连接超时时间和读取超时时间
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "Basic NGY3YWVmMzRmYjM2MTI5MmM1NjZhMWNkOjA1NGQ2MTAzODIzYTcyNmZjMTJkMDQ2Ng==");
//连接服务器
conn.connect();
// 取得输入流,并使用Reader读取
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
return null;
}
//关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result.toString();
}


}
3 changes: 1 addition & 2 deletions chatapp/src/main/res/layout/activity_finish_register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:layout_marginTop="20dip"
android:background="@drawable/blue_btn_selector"
android:enabled="false"
android:background="@color/blue_btn_normal"
android:text="完成"
android:textColor="@drawable/blue_text_selector"
android:textSize="16sp"/>
Expand Down

0 comments on commit 9f0701f

Please sign in to comment.