فهرست منبع

1.提交微信分享
2.提交运行直接走keystore(release模式方便测试微信)

zhangmengjie 5 سال پیش
والد
کامیت
067f6e8427

+ 3 - 3
android/app/build.gradle

@@ -117,9 +117,6 @@ android {
             keyPassword MYAPP_RELEASE_KEY_PASSWORD
         }
     }
-    sourceSets.main {
-        jniLibs.srcDir 'libs'
-    }
     splits {
         abi {
             reset()
@@ -134,6 +131,9 @@ android {
             proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
             signingConfig signingConfigs.release
         }
+        debug {
+            signingConfig signingConfigs.release
+        }
     }
     // applicationVariants are e.g. debug, release
     applicationVariants.all { variant ->

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 127 - 116
android/app/src/main/assets/index.android.bundle


+ 15 - 0
android/app/src/main/java/com/edufound/mobile/wxapi/WXEntryActivity.java

@@ -0,0 +1,15 @@
+package com.edufound.mobile.wxapi;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import com.theweflex.react.WeChatModule;
+
+public class WXEntryActivity extends Activity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        WeChatModule.handleIntent(getIntent());
+        finish();
+    }
+}

+ 16 - 0
android/app/src/main/java/com/edufound/mobile/wxapi/WXPayEntryActivity.java

@@ -0,0 +1,16 @@
+package com.edufound.mobile.wxapi;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import com.theweflex.react.WeChatModule;
+
+public class WXPayEntryActivity extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        WeChatModule.handleIntent(getIntent());
+        finish();
+    }
+}

+ 2 - 1
android/gradle.properties

@@ -19,4 +19,5 @@
 MYAPP_RELEASE_STORE_FILE=edufound.keystore
 MYAPP_RELEASE_KEY_ALIAS=edufound_key
 MYAPP_RELEASE_STORE_PASSWORD=edufound123
-MYAPP_RELEASE_KEY_PASSWORD=edufound321
+MYAPP_RELEASE_KEY_PASSWORD=edufound321
+

+ 4 - 2
pages/components/SharedDialog.js

@@ -222,10 +222,12 @@ export default class SharedDialog extends Component<Props> {
   }
 
   wechat() {
-    wechat.shareToSession("测试1", "测试1111111111111");
+    this.setModalVisible(false);
+    wechat.shareToSessionText("测试测试测试shareToSessionText");
   }
   circle() {
-    alert("circle");
+    this.setModalVisible(false);
+    wechat.shareToTimelineText("测试测试测试");
   }
 
   setModalVisible(visible) {

+ 87 - 84
pages/utils/request.js

@@ -2,46 +2,44 @@
  * 检查HTTP请求状态
  */
 function checkStatus(response) {
-    console.log('res1',response)
-    if (response.status >= 200 && response.status < 300) {
-        return response;
-    }
-    const error = new Error(response.statusText);
-    error.response = response;
-    throw error;
+  console.log("res1", response);
+  if (response.status >= 200 && response.status < 300) {
+    return response;
+  }
+  const error = new Error(response.statusText);
+  error.response = response;
+  throw error;
 }
 
 /**
  * 将Response内容转为JSON格式
  */
 function parseJSON(response) {
-    return response.json();
+  return response.json();
 }
 
 /**
  * 统一拦截接口返回数据的状态,提示错误消息
  */
 function checkAPIDatas(data) {
-    console.log('data',data)
-    if (!data.success) {
-        const code = data;
-    }
-    return data
+  console.log("data", data);
+  if (!data.success) {
+    const code = data;
+  }
+  return data;
 }
 
 function checkAPIError(err) {
-    console.log('err',err)
-    // const code = err.response.code;
-    // const status = err.response.status;
-    // const { url, type, oStatus, statusText } = err.response;
-    // Message.error(`地址:${url} 类型:${type} 状态:${oStatus} 信息:${statusText}`, 10);
-    return {
-        err
-    };
-
+  console.log("err", err);
+  // const code = err.response.code;
+  // const status = err.response.status;
+  // const { url, type, oStatus, statusText } = err.response;
+  // Message.error(`地址:${url} 类型:${type} 状态:${oStatus} 信息:${statusText}`, 10);
+  return {
+    err
+  };
 }
 
-
 /**
  * Requests a URL, returning a promise.
  * @param  {string} url       The URL we want to request
@@ -50,66 +48,71 @@ function checkAPIError(err) {
  */
 
 const request = async (url, options) => {
-    // global.storage.save({
-    //     key:'token',
-    //     data: '123123123123',
-    //     expires: null
+  // global.storage.save({
+  //     key:'token',
+  //     data: '123123123123',
+  //     expires: null
+  // });
+  if (options) {
+    const method = options.method.toUpperCase();
+    // switch(method){
+    //     case 'POST':
+    //             options.headers = {
+    //                 'Accept': 'application/json',
+    //                 'Content-Type': '"Content-Type": "application/json',
+    //                 "uid": 'c2e13090a563447c8744a8c03171d1db',
+    //                 'token': await storage.load({
+    //                     key: 'token'
+    //                 })
+    //             };
+    //         break;
+    //     case 'PUT':
+    //             options.headers = {
+    //                 'Accept': 'application/json',
+    //                 'Content-Type': 'application/x-www-form-urlencoded',
+    //                 "uid": 'c2e13090a563447c8744a8c03171d1db',
+    //                 // 'token': await storage.load({
+    //                 //     key: 'token'
+    //                 // })
+    //             };
+    //         break;
+    //         default:
+    //                 options.headers = {
+    //                     'token': await storage.load({
+    //                         key: 'token'
+    //                     })
+    //                 };
+    //             break;
+    // // }
+    // const token = await storage.load({
+    //     key: 'token'
     // });
-    if (options) {
-        const method = options.method.toUpperCase();
-        // switch(method){
-        //     case 'POST':
-        //             options.headers = {
-        //                 'Accept': 'application/json',
-        //                 'Content-Type': '"Content-Type": "application/json',
-        //                 "uid": 'c2e13090a563447c8744a8c03171d1db',
-        //                 'token': await storage.load({
-        //                     key: 'token'
-        //                 })
-        //             };
-        //         break;
-        //     case 'PUT':
-        //             options.headers = {
-        //                 'Accept': 'application/json',
-        //                 'Content-Type': 'application/x-www-form-urlencoded',
-        //                 "uid": 'c2e13090a563447c8744a8c03171d1db',
-        //                 // 'token': await storage.load({
-        //                 //     key: 'token'
-        //                 // })
-        //             };
-        //         break;
-        //         default:
-        //                 options.headers = {
-        //                     'token': await storage.load({
-        //                         key: 'token'
-        //                     })
-        //                 };
-        //             break;
-        // }
-        const token = await storage.load({
-            key: 'token'
-        });
-        if (method === 'POST' || method === 'PATCH' || method === 'DELETE' || method === 'PUT') {
-            options.headers = {
-                'Accept': 'application/json',
-                'Content-Type': 'application/json',
-                "uid": 'c2e13090a563447c8744a8c03171d1db',
-                'token': token?  token : null
-            };
-            options.body = JSON.stringify(options.body)
-        }else {
-            options.headers = {
-                'token': await storage.load({
-                    key: 'token'
-                })
-            };
-        }
+    if (
+      method === "POST" ||
+      method === "PATCH" ||
+      method === "DELETE" ||
+      method === "PUT"
+    ) {
+      options.headers = {
+        Accept: "application/json",
+        "Content-Type": "application/json",
+        uid: "c2e13090a563447c8744a8c03171d1db"
+        // 'token': token?  token : null
+      };
+      options.body = JSON.stringify(options.body);
+    } else {
+      options.headers = {
+        token: await storage.load({
+          key: "token"
+        })
+      };
     }
-    console.log('options',options)
-    return fetch(url, options)
-        .then(checkStatus)
-        .then(parseJSON)
-        .then(checkAPIDatas)
-        .catch(checkAPIError);
-}
-export default request
+  }
+  console.log("options", options);
+  return fetch(url, options)
+    .then(checkStatus)
+    .then(parseJSON)
+    .then(checkAPIDatas)
+    .catch(checkAPIError);
+};
+export default request;

+ 119 - 5
pages/utils/wechat.js

@@ -6,16 +6,95 @@ import * as WeChat from "react-native-wechat";
  */
 WeChat.registerApp("wx51acc19c8f7a0f6f");
 export default class wechat {
-  componentWillMount() {}
+  /**
+   * 好友文字分享
+   * @param  {string} descriptiontext      测试微信好友分享的文本内容
+   */
+  static shareToSessionText(descriptiontext) {
+    WeChat.isWXAppInstalled().then(isInstalled => {
+      if (isInstalled) {
+        WeChat.shareToSession({
+          type: "text",
+          description: descriptiontext
+        }).catch(error => {
+          console.log(error.message);
+        });
+      } else {
+        alert("请安装微信");
+      }
+    });
+  }
 
-  //文字好友分享
-  static shareToSession(text, description) {
-    console.log("123123123123123");
+  /**
+   * 微信好友分享链接
+   * @param  {string} title_text            分享的标题
+   * @param  {string} description_text      分享的标题内容
+   * @param  {string} thumbImage_url       分享的标题图片
+   * @param  {string} webpageUrl_url       分享的链接
+   */
+  static shareToSessionNews(
+    title_text,
+    description_text,
+    thumbImage_url,
+    webpageUrl_url
+  ) {
     WeChat.isWXAppInstalled().then(isInstalled => {
       if (isInstalled) {
         WeChat.shareToSession({
+          title: title,
+          description: description,
+          thumbImage: thumbImage,
+          type: "news",
+          webpageUrl: webpageUrl
+        }).catch(error => {
+          alert(error.message);
+        });
+      } else {
+        alert("请安装微信");
+      }
+    });
+  }
+
+  /**
+   * 微信朋友圈分享的文本
+   * @param  {string} description_text      测试微信朋友圈分享的文本内容
+   */
+  static shareToTimelineText(description_text) {
+    WeChat.isWXAppInstalled().then(isInstalled => {
+      if (isInstalled) {
+        WeChat.shareToTimeline({
           type: "text",
-          description: "测试微信好友分享的文本内容"
+          description: description_text
+        }).catch(error => {
+          console.log(error.message);
+        });
+      } else {
+        alert("请安装微信");
+      }
+    });
+  }
+
+  /**
+   * 微信好友分享链接
+   * @param  {string} title_text            分享的标题
+   * @param  {string} description_text      分享的标题内容
+   * @param  {string} thumbImage_url       分享的标题图片
+   * @param  {string} webpageUrl_url       分享的链接
+   */
+  static shareToTimelineNews(
+    title_text,
+    description_text,
+    thumbImage_url,
+    webpageUrl_url
+  ) {
+    WeChat.isWXAppInstalled().then(isInstalled => {
+      if (isInstalled) {
+        WeChat.shareToTimeline({
+          title: title_text,
+          description: description_text,
+          thumbImage: thumbImage_url,
+          type: "news",
+          webpageUrl: webpageUrl_url
         }).catch(error => {
           console.log(error.message);
         });
@@ -24,4 +103,39 @@ export default class wechat {
       }
     });
   }
+
+  /**
+   * 微信支付
+   * @param  {string} partnerId          商家向财付通申请的商家id
+   * @param  {string} prepayId           预支付订单
+   * @param  {string} nonceStr           随机串,防重发
+   * @param  {string} timeStamp          时间戳,防重发.
+   * @param  {string} package            商家根据财付通文档填写的数据和签名
+   * @param  {string} sign               商家根据微信开放平台文档对数据做的签名
+   */
+  static pay(partnerId, prepayId, nonceStr, timeStamp, packages, sign) {
+    WeChat.isWXAppInstalled().then(isInstalled => {
+      if (isInstalled) {
+        WeChat.pay({
+          partnerId: partnerId, // 商家向财付通申请的商家id
+          prepayId: prepayId, // 预支付订单
+          nonceStr: nonceStr, // 随机串,防重发
+          timeStamp: timeStamp, // 时间戳,防重发.
+          package: packages, // "Sign=WXPay", // 商家根据财付通文档填写的数据和签名
+          sign: sign // 商家根据微信开放平台文档对数据做的签名
+        })
+          .then(requestJson => {
+            //支付成功回调
+            if (requestJson.errCode == "0") {
+              //回调成功处理
+            }
+          })
+          .catch(err => {
+            alert("支付失败");
+          });
+      } else {
+        alert("请安装微信");
+      }
+    });
+  }
 }