Ver código fonte

Merge branch 'master' of http://gogs.efunbox.cn/Rorschach/efunbox-mobile-8

Limengbo 5 anos atrás
pai
commit
80831c09eb
6 arquivos alterados com 148 adições e 76 exclusões
  1. 41 41
      App.js
  2. 37 18
      pages/PhoneBind.js
  3. 9 6
      pages/components/PersonalInfo.js
  4. 14 10
      pages/services/user.js
  5. 13 0
      pages/utils/commonutil.js
  6. 34 1
      pages/utils/wechat.js

+ 41 - 41
App.js

@@ -6,53 +6,53 @@
  * @flow
  */
 
-import React, { Component } from "react";
-import {
-  AsyncStorage 
-} from "react-native";
-import { createStackNavigator, createAppContainer } from "react-navigation";
+import React, { Component } from 'react';
+import { AsyncStorage } from 'react-native';
+import { createStackNavigator, createAppContainer } from 'react-navigation';
 import Storage from 'react-native-storage';
-import MainActivity from "./pages/MainActivity";
-import SchoolAge from "./pages/components/SchoolAge";
-import MainPage from "./pages/components/MainPage";
-import SchedulePage from "./pages/components/SchedulePage";
-import PersonalInfo from "./pages/components/PersonalInfo";
-import CourseDetails from "./pages/CourseDetails";
-import userCenter from "./pages/userCenter";
-import Order from './pages/buy/order'
-import Ticket from './pages/buy/ticket'
-import Buy from './pages/buy/buy'
-import Login from './pages/Login'
-import SearchResult from './pages/searchResult'
+import MainActivity from './pages/MainActivity';
+import SchoolAge from './pages/components/SchoolAge';
+import MainPage from './pages/components/MainPage';
+import SchedulePage from './pages/components/SchedulePage';
+import PersonalInfo from './pages/components/PersonalInfo';
+import CourseDetails from './pages/CourseDetails';
+import userCenter from './pages/userCenter';
+import Order from './pages/buy/order';
+import Ticket from './pages/buy/ticket';
+import Buy from './pages/buy/buy';
+import Login from './pages/Login';
+import SearchResult from './pages/searchResult';
+import PhoneBind from './pages/PhoneBind';
 
 const RootNavigator = createStackNavigator(
-  {
-    MainActivity: { screen: MainActivity },
-    SchoolAge: { screen: SchoolAge },
-    MainPage: { screen: MainPage },
-    SchedulePage: { screen: SchedulePage },
-    PersonalInfo: { screen: PersonalInfo },
-    userCenter: { screen: userCenter },
-    CourseDetails: { screen: CourseDetails },
-    Order: { screen: Order },
-    Ticket: { screen: Ticket },
-    Login: { screen: Login },
-    Buy: { screen: Buy },
-    SearchResult: { screen: SearchResult },
-  },
-  {
-    initialRouteName: "MainPage",
-    headerMode: "null"
-  }
+	{
+		MainActivity: { screen: MainActivity },
+		SchoolAge: { screen: SchoolAge },
+		MainPage: { screen: MainPage },
+		SchedulePage: { screen: SchedulePage },
+		PersonalInfo: { screen: PersonalInfo },
+		userCenter: { screen: userCenter },
+		CourseDetails: { screen: CourseDetails },
+		Order: { screen: Order },
+		Ticket: { screen: Ticket },
+		Login: { screen: Login },
+		Buy: { screen: Buy },
+		SearchResult: { screen: SearchResult },
+		PhoneBind: { screen: PhoneBind }
+	},
+	{
+		initialRouteName: 'PersonalInfo',
+		headerMode: 'null'
+	}
 );
 const App = createAppContainer(RootNavigator);
 export default App;
 
 let storage = new Storage({
-  size: 1000,
-  storageBackend: AsyncStorage,
-  defaultExpires: null,
-  enableCache: true,
-})
+	size: 1000,
+	storageBackend: AsyncStorage,
+	defaultExpires: null,
+	enableCache: true
+});
 
-global.storage = storage
+global.storage = storage;

+ 37 - 18
pages/PhoneBind.js

@@ -25,12 +25,15 @@ import ShopBox from './components/ShopBox';
 import TopicTitle from './components/TopicTitle';
 import ScrollRow from './components/ScrollRow';
 import http_user from './services/user';
+import commonutil from './utils/commonutil';
 
 export default class PhoneBind extends BasePage {
 	state = {
 		type: '',
 		phone_num: '',
 		verification_text: '获取验证码',
+		verification_code: '',
+		http_verification_code: '',
 		page_title_text: '绑定手机号',
 		click_ok_text: '绑 定'
 	};
@@ -70,7 +73,9 @@ export default class PhoneBind extends BasePage {
 					</View>
 				</View>
 				<View style={styles.loginIn}>
-					<Text style={styles.loginText}>{this.state.click_ok_text}</Text>
+					<Text style={styles.loginText} onPress={this.clickOK.bind(this)}>
+						{this.state.click_ok_text}
+					</Text>
 				</View>
 				<View style={styles.wechatLogin}>
 					{/* <Image source={require('./images/common/wechat.png')} /> */}
@@ -101,12 +106,24 @@ export default class PhoneBind extends BasePage {
 
 	getVerification() {
 		if (this.state.verification_text === '获取验证码') {
-			if (this.isPoneAvailable(this.state.phone_num)) {
-				// http_user.getVerificationCode(this.state.phone_num);
-				this.setState({
-					verification_text: '60'
+			if (commonutil.isPoneAvailable(this.state.phone_num)) {
+				http_user.getVerificationCode(this.state.phone_num).then((result) => {
+					if (result.code != 200) {
+						ToastAndroid.show(result.message, ToastAndroid.SHORT);
+						return;
+					} else {
+						console.log('====================================');
+						console.log(result.data);
+						console.log('====================================');
+						this.setState({
+							http_verification_code: result.data
+						});
+					}
+					this.setState({
+						verification_text: '60'
+					});
+					this.CountDown();
 				});
-				this.CountDown();
 			} else {
 				ToastAndroid.show('请输入正确的手机号', ToastAndroid.SHORT);
 			}
@@ -120,27 +137,29 @@ export default class PhoneBind extends BasePage {
 				verification_text: '获取验证码'
 			});
 		} else {
-			console.log('====================================');
-			console.log(parseInt(this.state.verification_text) - 1 + '');
-			console.log('====================================');
 			setTimeout(() => {
 				this.setState({
 					verification_text: parseInt(this.state.verification_text) - 1 + ''
 				});
-				CountDown();
+				this.CountDown();
 			}, 1000);
 		}
 	}
 
-	//验证手机号
-	isPoneAvailable(str) {
-		let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
-		if (str.length == 0 || str == null) {
-			return false;
-		} else if (!myreg.test(str)) {
-			return false;
+	//绑定手机号
+	clickOK() {
+		if (this.state.http_verification_code == this.state.verification_code) {
+			let option = {
+				method: 'PUT', //请求方法
+				//请求体
+				body: {
+					mobile: this.state.phone_num,
+					sign: this.state.verification_code
+				}
+			};
+			http_user.bind_phone(option).then((result) => {});
 		} else {
-			return true;
+			ToastAndroid.show('验证码不正确', ToastAndroid.SHORT);
 		}
 	}
 }

+ 9 - 6
pages/components/PersonalInfo.js

@@ -15,6 +15,7 @@ import {
 	Image,
 	TouchableOpacity,
 	ImageBackground,
+	ToastAndroid,
 	Button,
 	StatusBar,
 	Modal,
@@ -822,13 +823,15 @@ export default class PersonalInfo extends BasePage {
 							nickName: result['nickname']
 						}
 					};
-					//接口不通
 					user.bind_wechat(opts).then((res) => {
-						console.log(res);
-						this.setState({
-							wechat_nickName: result['nickname'],
-							wechat_bind_color: 'rgba(113, 113, 113, 1)'
-						});
+						if (res.code == 200) {
+							this.setState({
+								wechat_nickName: res['nickname'],
+								wechat_bind_color: 'rgba(113, 113, 113, 1)'
+							});
+						} else {
+							ToastAndroid.show(res.message, ToastAndroid.SHORT);
+						}
 					});
 				});
 				break;

+ 14 - 10
pages/services/user.js

@@ -3,16 +3,16 @@ import efunRequest from '../utils/efunRequest';
 import request from '../utils/request';
 
 export default class user {
-  static update_UserInfo(opts) {
-    console.log('opts',opts);
-    return request(APIConfig.getUserUrl(``), opts);
-  }
-  // 个人中心
-  static userMember() {
-    return request(`http://ott80test-base.yifangjiaoyu.cn/mobile/user/member`, {
-      method: 'get'
-    });
-  }
+	static update_UserInfo(opts) {
+		console.log('opts', opts);
+		return request(APIConfig.getUserUrl(``), opts);
+	}
+	// 个人中心
+	static userMember() {
+		return request(`http://ott80test-base.yifangjiaoyu.cn/mobile/user/member`, {
+			method: 'get'
+		});
+	}
 	static update_UserInfo(opts) {
 		return request(APIConfig.getUserUrl(``), opts);
 	}
@@ -24,4 +24,8 @@ export default class user {
 	static getVerificationCode(phone) {
 		return request(APIConfig.getUserUrl(`/sendCode?mobile=` + phone));
 	}
+
+	static bind_phone(opts) {
+		return request(APIConfig.getUserUrl(`/mobileBind`), opts);
+	}
 }

+ 13 - 0
pages/utils/commonutil.js

@@ -0,0 +1,13 @@
+export default class commonutil {
+	//验证手机号
+	static isPoneAvailable(str) {
+		let myreg = /^[1][0-9]{10}$/;
+		if (str.length == 0 || str == null) {
+			return false;
+		} else if (!myreg.test(str)) {
+			return false;
+		} else {
+			return true;
+		}
+	}
+}

+ 34 - 1
pages/utils/wechat.js

@@ -165,7 +165,40 @@ export default class wechat {
 		});
 	}
 
-	//跳转小程序(需要改 react-native-wechat插件 1.删除react-native-android默认的jar包,直接引用微信官网的包。2.在react-native-wechat插件的index.js中,增加toMiniProgram方法)
+	/**
+	跳转小程序(需要改 react-native-wechat插件 
+	1.删除react-native-android默认的jar包,直接引用微信官网的包,或者下载官方最新包wechat-sdk-android-with-mta-x.x.x.jar
+	2.在react-native-wechat插件的index.js中,增加toMiniProgram方法)
+	3.在react-native-wechat插件WeChatModule中,删除旧的引用,增加新的引用
+			import com.tencent.mm.opensdk.constants.ConstantsAPI;
+			import com.tencent.mm.opensdk.modelbase.BaseReq;
+			import com.tencent.mm.opensdk.modelbase.BaseResp;
+			import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
+			import com.tencent.mm.opensdk.modelmsg.SendAuth;
+			import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
+			import com.tencent.mm.opensdk.modelmsg.WXFileObject;
+			import com.tencent.mm.opensdk.modelmsg.WXImageObject;
+			import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
+			import com.tencent.mm.opensdk.modelmsg.WXMusicObject;
+			import com.tencent.mm.opensdk.modelmsg.WXTextObject;
+			import com.tencent.mm.opensdk.modelmsg.WXVideoObject;
+			import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
+			import com.tencent.mm.opensdk.modelpay.PayReq;
+			import com.tencent.mm.opensdk.modelpay.PayResp;
+			import com.tencent.mm.opensdk.openapi.IWXAPI;
+			import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
+			import com.tencent.mm.opensdk.openapi.WXAPIFactory;
+		4.在react-native-wechat插件WeChatModule中,增加跳转小程序方法
+			@ReactMethod
+    	public void toMiniProgram(String programId, String path) {
+      	  WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
+      	  req.userName = programId; // 填小程序原始id
+       	 req.path = path;                  //拉起小程序页面的可带参路径,不填默认拉起小程序首页
+        	req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版,体验版和正式版
+        	api.sendReq(req);
+    }
+
+	 */
 	static toMiniProgram(programId, path) {
 		WeChat.toMiniProgram(programId, path);
 	}