作者 liming

sss

... ... @@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
android {
/* signingConfigs {
release {
keyAlias 'FireControl'
keyPassword '11111111'
storeFile file('./FireControl.jks')
storePassword '11111111'
}
}*/
signingConfigs {
debug {
storeFile file('D:\\project\\huahang_project\\app\\xuetubao.jks')
storePassword '111111'
keyAlias = 'xuetubao'
keyPassword '111111'
}
}
compileSdkVersion 28
defaultConfig {
... ... @@ -82,7 +82,7 @@ dependencies {
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
/* implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.jcodecraeer:xrecyclerview:1.5.9'*/
implementation 'com.jcodecraeer:xrecyclerview:1.5.9'*/
implementation 'com.android.support:recyclerview-v7:28.1.1'
implementation 'com.jcodecraeer:xrecyclerview:1.5.9'
implementation 'fm.jiecao:jiecaovideoplayer:5.5.2'
... ... @@ -92,11 +92,9 @@ dependencies {
implementation 'org.greenrobot:eventbus:3.1.1'
implementation files('libs/AMap3DMap_7.1.0_AMapSearch_7.1.0_AMapLocation_4.7.2_20191030.jar')
implementation 'com.youth.banner:banner:1.4.10'
// 微信
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
implementation 'com.zhy:okhttputils:2.4.1'
// implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
// implementation 'com.zhy:okhttputils:2.4.1'
//ijkplayer
implementation 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'
implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
... ... @@ -106,22 +104,18 @@ dependencies {
implementation 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-exo:0.8.8'
implementation 'com.hyman:flowlayout-lib:1.1.2'
//顶部导航栏
implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
//ijkplayer
implementation 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'
implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-exo:0.8.8'
implementation files('libs/umeng-share-wechat-simplify-6.9.2.jar')
}
... ...
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
... ... @@ -43,6 +43,20 @@
#保持泛型
-keepattributes Signature
#友盟
-keep class com.umeng.** {*;}
-keepclassmembers class * {
public <init> (org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class [com.hh.xuetubao].R$*{
public static final int *;
}
#保持所有实现 Serializable 接口的类成员
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
... ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.hh.xuetubao">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore="ProtectedPermissions" />
<!-- 允许程序访问WiFi网络信息 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 允许程序读写手机状态和身份 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- 允许程序访问CellID或WiFi热点来获取粗略的位置 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".MyApplication"
... ... @@ -150,8 +155,9 @@
<!-- 微信 -->
<activity
android:name=".wxapi.WXEntryActivity"
android:label="WXEntryActivity"
android:exported="true" />
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
</application>
... ...
... ... @@ -2,8 +2,8 @@ package com.hh.xuetubao;
import android.app.Application;
import android.content.Context;
import com.hh.xuetubao.wxapi.WxLogin;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
public class MyApplication extends Application {
... ... @@ -15,8 +15,18 @@ public class MyApplication extends Application {
super.onCreate();
sMyApplication = this;
WxLogin.initWx(this); // wx
/**
* 设置组件化的Log开关
* 参数: boolean 默认为false,如需查看LOG设置为true
*/
UMConfigure.setLogEnabled(true);
UMConfigure.init(this, "5dd8cf883fc195fb8d000b63", "学徒宝", UMConfigure.DEVICE_TYPE_PHONE, null);
}
{
PlatformConfig.setWeixin("wxcf11ff5e6b39916b", "1831891c2fe743e792b2290e822f29cc");
}
public static MyApplication getMyApplication() {
... ...
... ... @@ -23,6 +23,7 @@ import com.hh.xuetubao.bean.ResumeDetailBean;
import com.hh.xuetubao.bean.ResumedJobListBean;
import com.hh.xuetubao.bean.TranscriptBean;
import com.hh.xuetubao.bean.UserBean;
import com.hh.xuetubao.bean.WeixinBean;
import io.reactivex.Observable;
import retrofit2.http.Body;
... ... @@ -169,7 +170,7 @@ public interface MyServer {
* @return
*/
@GET("WeixinLogin")
Observable<UserBean> WeixinLogin(@Query("wxOpenId") String wxOpenId);
Observable<WeixinBean> WeixinLogin(@Query("wxOpenId") String wxOpenId, int logType);
/**
* 微信登录绑定接口
... ... @@ -190,7 +191,7 @@ public interface MyServer {
* @return
*/
@GET("AccountLogin")
Observable<UserBean> AccountLogin(@Query("account") String account, @Query("password") String password);
Observable<UserBean> AccountLogin(@Query("account") String account, @Query("password") String password,@Query("logType") int logtype);
@FormUrlEncoded
... ...
package com.hh.xuetubao.activity.login;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
... ... @@ -8,7 +9,9 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.hh.xuetubao.MainActivity;
import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
import com.hh.xuetubao.bean.UserBean;
import com.hh.xuetubao.model.AccountModel;
import com.hh.xuetubao.mvp.BaseMvpActivity;
... ... @@ -38,6 +41,8 @@ public class BdsjActivity extends BaseMvpActivity<CommonPresenter, AccountModel>
private CountDownTimer timer;
private int time = 60;
String openid;
@Override
public void initView() {
... ... @@ -50,7 +55,7 @@ public class BdsjActivity extends BaseMvpActivity<CommonPresenter, AccountModel>
@Override
public void initData() {
openid = getIntent().getStringExtra("AccountOid");
}
@Override
... ... @@ -107,6 +112,9 @@ public class BdsjActivity extends BaseMvpActivity<CommonPresenter, AccountModel>
case 3: // 绑定
UserBean bean1 = (UserBean) o;
if (bean1.getSuccess()) {
String accountOid = bean1.getAccountOid();
SharedPrefrenceUtils.saveString(this, "AccountOid", accountOid);
startActivity(new Intent(this, MainActivity.class));
Toast.makeText(this, "微信绑定成功", Toast.LENGTH_SHORT).show();
this.finish();
} else {
... ... @@ -149,7 +157,7 @@ public class BdsjActivity extends BaseMvpActivity<CommonPresenter, AccountModel>
Toast.makeText(this, "手机号和验证码不可为空", Toast.LENGTH_LONG).show();
return;
} else {
mPresenter.getPresenter(1, 3, edPhone.getText().toString().trim(), edCode.getText().toString().trim()); // - > 绑定
mPresenter.getPresenter(1, 3, openid,edPhone.getText().toString().trim(), edCode.getText().toString().trim()); // - > 绑定
}
break;
case R.id.bdsj_fhdl: // - > 返回登录
... ...
... ... @@ -112,7 +112,7 @@ public class JgdlActivity extends BaseMvpActivity<CommonPresenter, AccountModel>
Toast.makeText(this, "用户名和密码不可为空", Toast.LENGTH_SHORT).show();
return;
} else {
mPresenter.getPresenter(1, 4, edYhm.getText().toString().trim(), edPas.getText().toString().trim());
mPresenter.getPresenter(1, 4, edYhm.getText().toString().trim(), edPas.getText().toString().trim(),"2"); // android 为 2
}
break;
case R.id.jgdl_fhdl: // - > 返回登录
... ...
... ... @@ -15,15 +15,16 @@ import com.hh.xuetubao.MainActivity;
import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
import com.hh.xuetubao.bean.UserBean;
import com.hh.xuetubao.bean.WeixinBean;
import com.hh.xuetubao.model.AccountModel;
import com.hh.xuetubao.mvp.BaseMvpActivity;
import com.hh.xuetubao.mvp.CommonPresenter;
import com.hh.xuetubao.mvp.ICommonView;
import com.hh.xuetubao.wxapi.WxLogin;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
... ... @@ -134,7 +135,19 @@ public class LoginActivity extends BaseMvpActivity<CommonPresenter, AccountModel
Toast.makeText(this, bean.getErrorMsg(), Toast.LENGTH_LONG).show();
Toast.makeText(this, "登录失败", Toast.LENGTH_LONG).show();
}
}
if (api == 1 && intent == 6) {
WeixinBean weixinBean = (WeixinBean) o;
if (weixinBean.isIsBindWx() == true) { // 已经绑定
String accountOid = weixinBean.getAccountOid();
SharedPrefrenceUtils.saveString(this, "AccountOid", accountOid);
startActivity(new Intent(this, MainActivity.class));
} else {
Intent intent1 = new Intent(this, BdsjActivity.class);
intent1.putExtra("AccountOid", weixinBean.getAccountOid());
startActivity(intent1);
}
}
}
... ... @@ -155,14 +168,12 @@ public class LoginActivity extends BaseMvpActivity<CommonPresenter, AccountModel
ButterKnife.bind(this);
}
IWXAPI api;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login:
if (isCellphone(edPhone.getText().toString()) && !TextUtils.isEmpty(edPhone.getText().toString()))
mPresenter.getPresenter(1, 2, edPhone.getText().toString(), edCode.getText().toString(),String.valueOf(2));
mPresenter.getPresenter(1, 2, edPhone.getText().toString(), edCode.getText().toString(), String.valueOf(2));
else
Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_LONG).show();
break;
... ... @@ -174,8 +185,9 @@ public class LoginActivity extends BaseMvpActivity<CommonPresenter, AccountModel
Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_LONG).show();
break;
case R.id.img_wechat: // 微信
WxLogin.longWx();
// startActivity(new Intent(LoginActivity.this, BdsjActivity.class));
UMShareAPI.get(this).doOauthVerify(this, SHARE_MEDIA.WEIXIN, authListener);
break;
case R.id.img_jigou: // 机构登录
startActivity(new Intent(LoginActivity.this, JgdlActivity.class));
... ... @@ -189,5 +201,44 @@ public class LoginActivity extends BaseMvpActivity<CommonPresenter, AccountModel
return matcher.matches();
}
// // 监听
UMAuthListener authListener = new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA platform) {
Toast.makeText(LoginActivity.this, "开始", Toast.LENGTH_LONG).show();
}
@Override
public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> map) {
if (map == null) {
Toast.makeText(LoginActivity.this, "请检查是否安装该应用", Toast.LENGTH_SHORT).show();
return;
}
String openid = map.get("openid"); // openid
String name = map.get("name"); // name
String gender = map.get("gender"); // 性别
String sex = "0";
if (!TextUtils.isEmpty(gender) && gender.equals("男")) {
sex = "1";
} else if (!TextUtils.isEmpty(gender) && gender.equals("女")) {
sex = "2";
}
//头像
String iconurl = map.get("iconurl");
mPresenter.getPresenter(1, 6, openid, "2"); // android
}
@Override
public void onError(SHARE_MEDIA platform, int action, Throwable t) {
}
@Override
public void onCancel(SHARE_MEDIA platform, int action) {
}
};
}
... ...
... ... @@ -2,6 +2,7 @@ package com.hh.xuetubao.activity.pratice;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
... ... @@ -9,6 +10,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
import com.hh.xuetubao.bean.UserBean;
... ... @@ -54,6 +56,7 @@ public class MockExamActivity extends BaseMvpActivity<CommonPresenter, ExerciseM
resumeOid = SharedPrefrenceUtils.getString(this, "AccountOid");
catalogOid = getIntent().getStringExtra("catalogOid") + "";
Log.e("resumeOid", resumeOid);
Log.e("catalogOid", catalogOid);
linTrain.setOnClickListener(this);
... ... @@ -67,6 +70,7 @@ public class MockExamActivity extends BaseMvpActivity<CommonPresenter, ExerciseM
@Override
public void initData() {
mPresenter.getPresenter(3, 1, catalogOid, resumeOid);
mPresenter.getPresenter( 5, 4, resumeOid);
}
@Override
... ... @@ -92,6 +96,27 @@ public class MockExamActivity extends BaseMvpActivity<CommonPresenter, ExerciseM
if (bean.getExamType() != null)
content.setText(bean.getExamType());
}
if (api == 5 && intent == 4) {
UserBean bean = (UserBean) o;
String userName = SharedPrefrenceUtils.getString(MockExamActivity.this, "UserName");
if (bean.getUserName() != null) {
name.setText(bean.getUserName());
}else {
name.setText(userName);
}
String reallHeader = SharedPrefrenceUtils.getString(MockExamActivity.this, "ReallHeader");
String headPic = SharedPrefrenceUtils.getString(MockExamActivity.this, "HeadPic");
if (!TextUtils.isEmpty(headPic)) {
Glide.with(this).load(headPic).into(image);
} else if (!TextUtils.isEmpty(reallHeader)) {
Glide.with(this).load(reallHeader).into(image);
} else if (bean.getHeadPic() != null && !bean.getHeadPic().equals("")) {
Glide.with(MockExamActivity.this).load(bean.getHeadPic()).into(image);
}
}
... ...
package com.hh.xuetubao.adapter;
import android.content.Context;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
... ... @@ -39,8 +41,10 @@ public class StudyXrecAdapter extends RecyclerView.Adapter<StudyXrecAdapter.View
holder.percent.setText(String.valueOf(list.get(position).getStudyPercent()));
if (list.get(position).getLatelyStudyTime() != null)
holder.time.setText(list.get(position).getLatelyStudyTime());
if (list.get(position).getLatelyResourceName() != null)
if (list.get(position).getLatelyResourceName() != null) {
// holder.resourse.setText(list.get(position).getLatelyResourceName());
holder.resourse.setText(list.get(position).getLatelyResourceName());
}
if (list.get(position).getCoverPic() != null)
Glide.with(context).load(list.get(position).getCoverPic()).into(holder.img);
... ... @@ -73,7 +77,7 @@ public class StudyXrecAdapter extends RecyclerView.Adapter<StudyXrecAdapter.View
title = (TextView) itemView.findViewById(R.id.title);
percent = (TextView) itemView.findViewById(R.id.tv_percent);
img = (ImageView) itemView.findViewById(R.id.img);
resourse = (TextView) itemView.findViewById(R.id.tv_resourse);
resourse = itemView.findViewById(R.id.tv_resourse);
}
}
... ... @@ -86,4 +90,24 @@ public class StudyXrecAdapter extends RecyclerView.Adapter<StudyXrecAdapter.View
public interface TurnTo {
void turn(String LessonOid);
}
/**
* 半角转换为全角
*
* @param input
* @return
*/
public static String ToDBC(String input) {
char[] c = input.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == 12288) {// 全角空格为12288,半角空格为32
c[i] = (char) 32;
continue;
}
if (c[i] > 65280 && c[i] < 65375)// 其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
c[i] = (char) (c[i] - 65248);
}
return new String(c);
}
}
... ...
package com.hh.xuetubao.bean;
public class WeixinBean {
/**
* IsSuccess : true
* AccountOid : 16EA2C01-20E3-420D-AB4E-4E44F0539349
* IsBindWx : true
*/
private boolean IsSuccess;
private String AccountOid;
private boolean IsBindWx;
public boolean isIsSuccess() {
return IsSuccess;
}
public void setIsSuccess(boolean IsSuccess) {
this.IsSuccess = IsSuccess;
}
public String getAccountOid() {
return AccountOid;
}
public void setAccountOid(String AccountOid) {
this.AccountOid = AccountOid;
}
public boolean isIsBindWx() {
return IsBindWx;
}
public void setIsBindWx(boolean IsBindWx) {
this.IsBindWx = IsBindWx;
}
}
... ...
... ... @@ -30,9 +30,12 @@ public class AccountModel implements ICommonModel {
if (api == 1 && intent == 4) { // - > 机构登录
jg_login(commonView, api, intent, params);
}
if(api == 1 && intent == 5){ // 忘记密码
if (api == 1 && intent == 5) { // 忘记密码
forget_pas(commonView, api, intent, params);
}
if (api == 1 && intent == 6) { // 微信登录
weixin_login(commonView, api, intent, params);
}
}
... ... @@ -55,7 +58,7 @@ public class AccountModel implements ICommonModel {
/* 验证码登录 */
private void mobileLogin(final ICommonView commonView, final int api, final int intent, String... params) {
if (api == 1 && intent == 2)
mServers.mobileLogin(params[0], params[1],Integer.valueOf(params[2]))
mServers.mobileLogin(params[0], params[1], Integer.valueOf(params[2]))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObsever() {
... ... @@ -87,7 +90,7 @@ public class AccountModel implements ICommonModel {
/* 机构登录 */
private void jg_login(final ICommonView commonView, final int api, final int tag, String... params) {
if (api == 1 && tag == 4) {
mServers.AccountLogin(params[0], params[1])
mServers.AccountLogin(params[0], params[1], Integer.valueOf(params[2]))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObsever() {
... ... @@ -116,4 +119,20 @@ public class AccountModel implements ICommonModel {
}
}
/* 微信登录 */
private void weixin_login(final ICommonView commonView, final int api, final int tag, String... params) {
if(api ==1 && tag == 6){
mServers.WeixinLogin(params[0], Integer.valueOf(params[1]))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObsever() {
@Override
public void onNext(Object value) {
super.onNext(value);
commonView.getData(value, api, tag);
}
});
}
}
}
... ...
... ... @@ -51,6 +51,36 @@ public class ExerciseModel implements ICommonModel {
if (api == 9 && intent == 1)
DeleteExamRecordInfo(commonView, api, intent, params);
if(api == 5 && intent == 4){
GetHeadInfo(commonView, api, intent, params);
}
}
private void GetHeadInfo(final ICommonView commonView, final int api, final int intent, String... params) {
if (api == 5 && intent == 4)
mServers.GetHeadInfo(params[0])
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObsever() {
@Override
public void onNext(Object value) {
super.onNext(value);
commonView.getData(value, api, intent);
}
@Override
public void onError(Throwable e) {
super.onError(e);
commonView.onError(e, api);
}
@Override
public void onComplete() {
super.onComplete();
commonView.onComplete(api);
}
});
}
private void DeleteExamRecordInfo(final ICommonView commonView, final int api, final int intent, String... params) {
... ...
package com.hh.xuetubao.wxapi;
import android.content.Context;
import android.widget.Toast;
/**
* Created by 14178 on 2018/1/19.
*/
public class UIUtils {
private static Context mContext;
public static void initContext(Context context) {
mContext = context;
}
public static void runOnUIToast(String str){
Toast.makeText(mContext, str, Toast.LENGTH_SHORT).show();
}
}
package com.hh.xuetubao.wxapi;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.UserBean;
import com.hh.xuetubao.model.AccountModel;
import com.hh.xuetubao.mvp.BaseMvpActivity;
import com.hh.xuetubao.mvp.CommonPresenter;
import com.hh.xuetubao.mvp.ICommonView;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import com.umeng.socialize.weixin.view.WXCallbackActivity;
import org.json.JSONException;
import org.json.JSONObject;
public class WXEntryActivity extends WXCallbackActivity {
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class WXEntryActivity extends BaseMvpActivity<CommonPresenter, AccountModel> implements ICommonView, IWXAPIEventHandler {
private static final int RETURN_MSG_TYPE_LOGIN = 1;
private static final int RETURN_MSG_TYPE_SHARE = 2;
private IWXAPI mWeixinAPI;
@BindView(R.id.ed_phone)
EditText edPhone;
@BindView(R.id.ed_code)
EditText edCode;
@BindView(R.id.tv_yanzheng)
TextView tvYanzheng;
@BindView(R.id.bdsj_sure)
TextView bdsjSure;
@BindView(R.id.bdsj_fhdl)
TextView bdsjFhdl;
private CountDownTimer timer;
private int time = 60;
@Override
public void initView() {
ButterKnife.bind(this);
mWeixinAPI = WXAPIFactory.createWXAPI(this, WxData.WEIXIN_APP_ID, true);
mWeixinAPI.handleIntent(this.getIntent(), this);
}
@Override
public int initLayout() {
return R.layout.activity_bdsj; // R.layout.activity_wxentry
}
@Override
public void initData() {
}
@Override
public CommonPresenter getPresenter() {
return new CommonPresenter();
}
@Override
public AccountModel getModel() {
return new AccountModel();
}
@Override
public void getData(Object o, int api, int intent) {
if (api != 1) {
return;
}
switch (intent) {
case 1: // 验证码
UserBean bean = (UserBean) o;
if (bean.getSuccess()) {
Toast.makeText(this, "验证码发送成功", Toast.LENGTH_LONG).show();
time = 60;
timer = new CountDownTimer(60000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
time--;
tvYanzheng.setText(String.valueOf(time) + "s");
tvYanzheng.setFocusable(false);
tvYanzheng.setFocusableInTouchMode(false);
tvYanzheng.setClickable(false);
try {
tvYanzheng.setText(String.valueOf(time) + "s");
tvYanzheng.setFocusable(false);
} catch (Exception e) {
Log.e("zhangtao", e.toString());
}
}
@Override
public void onFinish() {
tvYanzheng.setText("获取验证码");
tvYanzheng.setFocusable(true);
tvYanzheng.setFocusableInTouchMode(true);
tvYanzheng.setClickable(true);
time = 60;
}
}.start();
} else {
Toast.makeText(this, "验证码发送失败", Toast.LENGTH_SHORT).show();
}
break;
case 3: // 绑定
UserBean bean1 = (UserBean) o;
if (bean1.getSuccess()) {
Toast.makeText(this, "微信绑定成功", Toast.LENGTH_SHORT).show();
this.finish();
} else {
Toast.makeText(this, "微信绑定失败", Toast.LENGTH_SHORT).show();
}
break;
}
}
@OnClick({R.id.tv_yanzheng, R.id.bdsj_sure, R.id.bdsj_fhdl})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.tv_yanzheng: // - > 验证码
if (isCellphone(edPhone.getText().toString()))
mPresenter.getPresenter(1, 1, edPhone.getText().toString(), String.valueOf(1)); // 1 -> 微信或手机号码绑定时发送
else
Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_LONG).show();
break;
case R.id.bdsj_sure: // - > 确定
if (isCellphone(edPhone.getText().toString())) {
Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_LONG).show();
return;
} else if (edPhone.getText().length() > 0 && edCode.getText().length() > 0) {
Toast.makeText(this, "手机号和验证码不可为空", Toast.LENGTH_LONG).show();
return;
} else {
mPresenter.getPresenter(1, 3, edPhone.getText().toString().trim(), edCode.getText().toString().trim()); // - > 绑定
}
break;
case R.id.bdsj_fhdl: // - > 返回登录
this.finish();
break;
}
}
public static boolean isCellphone(String str) {
Pattern pattern = Pattern.compile("^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))\\d{8}$");
Matcher matcher = pattern.matcher(str);
return matcher.matches();
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
mWeixinAPI.handleIntent(intent, this);//必须调用此句话
}
@Override
public void onReq(BaseReq baseReq) {
Log.e("-----", "onReq: " + baseReq);
finish();
}
@Override
public void onResp(BaseResp baseResp) {
Log.e("-----", "errStr: " + baseResp.errStr);
Log.e("-----", "openId: " + baseResp.openId);
Log.e("-----", "transaction: " + baseResp.transaction);
Log.e("-----", "errCode: " + baseResp.errCode);
Log.e("-----", "getType: " + baseResp.getType());
Log.e("-----", "checkArgs: " + baseResp.checkArgs());
switch (baseResp.errCode) {
case BaseResp.ErrCode.ERR_AUTH_DENIED:
case BaseResp.ErrCode.ERR_USER_CANCEL:
if (RETURN_MSG_TYPE_SHARE == baseResp.getType()) UIUtils.runOnUIToast("分享失败");
else UIUtils.runOnUIToast("登录失败");
break;
case BaseResp.ErrCode.ERR_OK:
switch (baseResp.getType()) {
case RETURN_MSG_TYPE_LOGIN:
//拿到了微信返回的code,立马再去请求access_token
String code = ((SendAuth.Resp) baseResp).code;
getAccess_token(code);
//就在这个地方,用网络库什么的或者自己封的网络api,发请求去咯,注意是get请求
Log.e("--------", "code: " + code);
// id_tv.setText("code: " + code); //
break;
case RETURN_MSG_TYPE_SHARE:
UIUtils.runOnUIToast("微信分享成功");
finish();
break;
}
break;
}
}
/**
* 获取openid accessToken值用于后期操作
*
* @param code 请求码
*/
private void getAccess_token(final String code) {
String path = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="
+ WxData.WEIXIN_APP_ID
+ "&secret="
+ WxData.APP_SECRET
+ "&code="
+ code
+ "&grant_type=authorization_code";
OkHttpUtils.get().url(path).build().execute(new StringCallback() {
@Override
public void onError(okhttp3.Call call, Exception e) {
}
@Override
public void onResponse(String response) {
Log.e("-----", "onResponse: " + response);
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
String openid = jsonObject.getString("openid").toString().trim();
String access_token = jsonObject.getString("access_token").toString().trim();
getUserMesg(access_token, openid);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
/**
* 获取微信的个人信息
*
* @param access_token
* @param openid
*/
private void getUserMesg(final String access_token, final String openid) {
String path = "https://api.weixin.qq.com/sns/userinfo?access_token="
+ access_token
+ "&openid="
+ openid;
OkHttpUtils.get().url(path).build().execute(new StringCallback() {
@Override
public void onError(okhttp3.Call call, Exception e) {
}
@Override
public void onResponse(String response) {
Log.e("------", "全部数据: " + response);
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
String nickname = jsonObject.getString("nickname");
int sex = Integer.parseInt(jsonObject.get("sex").toString());
String headimgurl = jsonObject.getString("headimgurl");
String openid1 = jsonObject.getString("openid");
Log.e("---", "用户基本信息:");
Log.e("---", "nickname:" + nickname);
// nickname_tv.setText("nickname: " +nickname);
Log.e("---", "sex: " + sex);
// sex_tv.setText("sex: " + sex + "");
Log.e("---", "headimgurl:" + headimgurl);
// startLoca(nickname, openid1);
} catch (JSONException e) {
e.printStackTrace();
UIUtils.runOnUIToast("登陆错误,请重新再试");
}
// finish();
}
});
}
@Override
public void onComplete(int api) {
}
@Override
public void onError(Throwable e, int api) {
}
}
... ...
package com.hh.xuetubao.wxapi;
/**
* XINHAO_HAN存储信息
*/
public class WxData {
/**
* 你的AppID
*
* 在此特别注意,本Demo只适用微信的登陆功能,并不能用到微信支付功能
*
* 在此注意,必须要和微信官网签名一致,否则调用不起来微信APP,
*
* 如果在你调用出错的情况下(微信APP死活不出来的情况下),请参阅作者简书网址 : https://www.jianshu.com/p/04ed0b65f3df
*
* 微信APP掉不出来:有以下原因:
*
* 1.签名不正确(APK所使用签名的MD5码) 签名MD5码不要有 : 如A0:5B:12:63.... ,要全部是小写(推荐)a05b1263...,这种形式的
*
* 2.APP_ID不正确
*
* 3.密匙不正确
*
* 4.包名不正确
*
* 不走回调WXEntryActivity
*
* 1.AndroidManifest.xml里没有配置
*
* <activity
* android:name=".wxapi.WXEntryActivity"
* android:exported="true"
* android:label="WXEntryActivity" />
* 2.必须是 你的包名.wxapi
* 如果你的所有信息填写正确,还是掉不起来微信,那就可能是微信服务器问题,请稍等3-5分钟,在尝试调用,否则就重复以上选项
* 大兄弟,记得细心一点哟~~~
*
*
*
*
*/
public static final String WEIXIN_APP_ID = "";
public static final String APP_SECRET = "";
/**
* 固定的
*
*/
public static final String SCOPE = "snsapi_userinfo";
public static final String STATE = "wechat_sdk_demo_test_neng";
}
package com.hh.xuetubao.wxapi;
import android.content.Context;
import android.widget.Toast;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
/**
* Created by 14178 on 2018/1/19.
*/
public class WxLogin {
public static IWXAPI api;
public static Context mContext;
/**
* 急的初始化
*
* @param context
*/
public static void initWx(Context context) {
UIUtils.initContext(context);
mContext = context;
api = WXAPIFactory.createWXAPI(context, WxData.WEIXIN_APP_ID, true);
api.registerApp(WxData.WEIXIN_APP_ID);
final IWXAPI msgApi = WXAPIFactory.createWXAPI(context, null);
// 将该app注册到微信
msgApi.registerApp(WxData.WEIXIN_APP_ID);
}
public static void longWx() {
if (mContext == null) {
Toast.makeText(mContext, "你没有初始化,请在Application中做初始化动作,请调用 initWx(context)方法", Toast.LENGTH_SHORT).show();
return;
}
if (!api.isWXAppInstalled()) {
Toast.makeText(mContext, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
return;
}
final SendAuth.Req req = new SendAuth.Req();
req.scope = WxData.SCOPE;
req.state = WxData.STATE;
api.sendReq(req);
}
}
... ... @@ -9,6 +9,7 @@
android:layout_height="@dimen/dp_90"
android:src="@mipmap/ic_launcher"
android:scaleType="fitXY"
android:layout_marginTop="@dimen/dp_20"
/>
<LinearLayout
... ... @@ -16,6 +17,7 @@
android:layout_height="@dimen/dp_90"
android:orientation="vertical"
android:layout_toRightOf="@id/img"
android:layout_marginTop="@dimen/dp_20"
>
<TextView
... ... @@ -24,7 +26,7 @@
android:layout_height="wrap_content"
android:layout_alignTop="@id/img"
android:layout_marginLeft="@dimen/dp_25"
android:layout_marginTop="@dimen/dp_25"
android:layout_marginTop="@dimen/dp_24"
android:text="ABB初级工程师证书"
android:textColor="#555555"
android:textSize="15sp"
... ... @@ -36,14 +38,12 @@
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:layout_marginLeft="@dimen/dp_25"
android:layout_marginTop="@dimen/dp_15"
android:layout_marginTop="@dimen/dp_13"
android:layout_toRightOf="@+id/img"
android:text="2010.07-2018.06"
android:textColor="#AAAAAA"
android:textSize="12sp" />
</LinearLayout>
<View
... ...
... ... @@ -6,7 +6,9 @@
<FrameLayout
android:id="@+id/frame"
android:layout_width="@dimen/dp_165"
android:layout_height="@dimen/dp_93">
android:layout_height="@dimen/dp_93"
android:layout_marginRight="@dimen/dp_15"
>
<ImageView
android:id="@+id/img"
... ... @@ -96,13 +98,15 @@
android:layout_toRightOf="@id/tv_free"
android:text="机器人编程方式 拷贝"
android:textColor="#349DFF"
android:textSize="13sp" />
android:textSize="13sp"
android:maxLines="2"
/>
<TextView
android:id="@+id/tv_recently"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_free"
android:layout_below="@id/tv_resourse"
android:layout_marginLeft="@dimen/dp_9"
android:layout_marginTop="@dimen/dp_13"
android:layout_toRightOf="@id/frame"
... ... @@ -114,7 +118,7 @@
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_free"
android:layout_below="@id/tv_resourse"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginTop="@dimen/dp_13"
android:layout_toRightOf="@id/tv_recently"
... ...
不能预览此文件类型
... ... @@ -7,9 +7,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.novoda:bintray-release:0.9'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
... ... @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
}
}
... ...
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
... ...