├── Example ├── .watchmanconfig ├── react-native-wechat.js ├── android │ ├── settings.gradle │ ├── app │ │ ├── src │ │ │ └── main │ │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ └── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── MainActivity.java │ │ ├── proguard-rules.pro │ │ ├── build.gradle │ │ └── react.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── ios │ ├── Example.xcodeproj │ │ ├── xcuserdata │ │ │ ├── yorkieliu.xcuserdatad │ │ │ │ ├── xcdebugger │ │ │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ │ └── xcschemes │ │ │ │ │ └── xcschememanagement.plist │ │ │ └── yorkie.xcuserdatad │ │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ ├── yorkie.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ │ └── yorkieliu.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Example.xcscheme │ └── Example │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── AppDelegate.m │ │ └── Base.lproj │ │ └── LaunchScreen.xib ├── README.md ├── package.json ├── index.android.js ├── .flowconfig └── index.ios.js ├── _config.yml ├── weixin.png ├── qrcode_qq.jpg ├── ios ├── libWeChatSDK.a ├── RCTWeChat.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcuserdata │ │ │ ├── puti.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ ├── yorkie.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── yorkieliu.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── xcuserdata │ │ ├── puti.xcuserdatad │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ ├── yorkieliu.xcuserdatad │ │ │ └── xcschemes │ │ │ │ ├── xcschememanagement.plist │ │ │ │ └── RCTWeChat.xcscheme │ │ └── yorkie.xcuserdatad │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ ├── xcshareddata │ │ └── xcschemes │ │ │ ├── RCTWeChat.xcscheme │ │ │ └── RCTWeChatTests.xcscheme │ └── project.pbxproj ├── RCTWeChatTests │ ├── Info.plist │ └── RCTWeChatTests.m ├── RCTWeChat.h ├── WechatAuthSDK.h ├── RCTWeChat.podspec ├── WXApi.h ├── RCTWeChat.m └── WXApiObject.h ├── qrcode_gitter.jpg ├── qrcode_dingding.jpg ├── .npmignore ├── .gitignore ├── yarn.lock ├── .idea └── react-native-wechat.iml ├── android ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── theweflex │ │ └── react │ │ ├── WeChatRegister.java │ │ ├── WeChatPackage.java │ │ └── WeChatModule.java ├── build.gradle └── react-native-wechat.iml ├── .travis.yml ├── package.json ├── LICENSE ├── react-native-wechat.podspec ├── docs ├── build-setup-ios.md └── build-setup-android.md ├── CODE_OF_CONDUCT.md ├── index.js └── README.md /Example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-merlot -------------------------------------------------------------------------------- /Example/react-native-wechat.js: -------------------------------------------------------------------------------- 1 | ../index.js -------------------------------------------------------------------------------- /weixin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/weixin.png -------------------------------------------------------------------------------- /Example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Example' 2 | 3 | include ':app' 4 | -------------------------------------------------------------------------------- /qrcode_qq.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/qrcode_qq.jpg -------------------------------------------------------------------------------- /ios/libWeChatSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/ios/libWeChatSDK.a -------------------------------------------------------------------------------- /qrcode_gitter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/qrcode_gitter.jpg -------------------------------------------------------------------------------- /qrcode_dingding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/qrcode_dingding.jpg -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /android/build 3 | /android/RCTWeChat.iml 4 | 5 | Example 6 | *.jpg 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | node_modules 4 | /android/build 5 | /android/RCTWeChat.iml 6 | 7 | # ios 8 | ios/build -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Example 3 | 4 | -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/Example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/xcuserdata/yorkieliu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/project.xcworkspace/xcuserdata/puti.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/ios/RCTWeChat.xcodeproj/project.xcworkspace/xcuserdata/puti.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | events@1.0.2: 6 | version "1.0.2" 7 | resolved "https://registry.yarnpkg.com/events/-/events-1.0.2.tgz#75849dcfe93d10fb057c30055afdbd51d06a8e24" 8 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/project.xcworkspace/xcuserdata/yorkie.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/ios/RCTWeChat.xcodeproj/project.xcworkspace/xcuserdata/yorkie.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 6 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/project.xcworkspace/xcuserdata/yorkieliu.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/ios/RCTWeChat.xcodeproj/project.xcworkspace/xcuserdata/yorkieliu.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/project.xcworkspace/xcuserdata/yorkie.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/Example/ios/Example.xcodeproj/project.xcworkspace/xcuserdata/yorkie.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/project.xcworkspace/xcuserdata/yorkieliu.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puti94/react-native-wechat/HEAD/Example/ios/Example.xcodeproj/project.xcworkspace/xcuserdata/yorkieliu.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Example/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Example for react-native-wechat 3 | 4 | Install the react-native at first: 5 | 6 | ``` 7 | $ npm install 8 | ``` 9 | 10 | Link the following: 11 | 12 | - RCTWeChat 13 | - CoreTelephony.framework 14 | - libsqlite3.0 15 | - libc++ 16 | - libz 17 | 18 | Click "Run" at your Xcode. 19 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node_modules/react-native/packager/packager.sh", 7 | "postinstall": "ln -sf ../index.js ./react-native-wechat.js" 8 | }, 9 | "dependencies": { 10 | "es6-promisify": "^3.0.0", 11 | "react-native": "^0.14.2", 12 | "events": "1.0.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/xcuserdata/yorkie.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SuppressBuildableAutocreation 6 | 7 | 13B07F861A680F5B00A75B9A 8 | 9 | primary 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/react-native-wechat.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/ios/Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.3.1' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Example/ios/Example/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | #import "AppDelegate.h" 13 | 14 | int main(int argc, char * argv[]) { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/xcuserdata/puti.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RCTWeChat.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 2 11 | 12 | RCTWeChatTests.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 3 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | defaultConfig { 7 | minSdkVersion 16 8 | targetSdkVersion 22 9 | versionCode 1 10 | versionName "1.0" 11 | ndk { 12 | abiFilters "armeabi-v7a", "x86" 13 | } 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | maven { url "$projectDir/../../react-native/android" } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile 'com.facebook.react:react-native:+' 26 | compile 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+' 27 | } 28 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/xcuserdata/yorkieliu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RCTWeChat.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 86D238411BD0BB9E00C75D01 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /android/src/main/java/com/theweflex/react/WeChatRegister.java: -------------------------------------------------------------------------------- 1 | package com.theweflex.react; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.util.Log; 7 | 8 | import com.tencent.mm.opensdk.openapi.IWXAPI; 9 | import com.tencent.mm.opensdk.openapi.WXAPIFactory; 10 | 11 | public class WeChatRegister extends BroadcastReceiver { 12 | 13 | private static final String TAG = "WeChatRegister"; 14 | @Override 15 | public void onReceive(Context context, Intent intent) { 16 | Log.e(TAG, "onReceive: "); 17 | // final IWXAPI api = WXAPIFactory.createWXAPI(context, WeChatModule.appId); 18 | // api.registerApp(WeChatModule.appId); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/xcuserdata/yorkieliu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Example.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 00E356ED1AD99517003FC87E 16 | 17 | primary 18 | 19 | 20 | 13B07F861A680F5B00A75B9A 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ios/RCTWeChatTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "7.1" 4 | sudo: false 5 | cache: 6 | directories: 7 | - $HOME/.yarn-cache 8 | - $HOME/.gradle/caches/ 9 | - $HOME/.gradle/wrapper/ 10 | env: 11 | - NODE_ENV='test' 12 | install: 13 | - npm install 14 | script: 15 | - npm test 16 | matrix: 17 | include: 18 | - language: android 19 | os: linux 20 | jdk: oraclejdk8 21 | before_cache: 22 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 23 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 24 | node_js: false 25 | - nvm install 7 26 | android: 27 | components: 28 | - android-23 29 | - build-tools-23.0.1 30 | - language: objective-c 31 | os: osx 32 | osx_image: xcode8.2 33 | node_js: false 34 | xcode_project: ios/RCTWeChat.xcodeproj 35 | xcode_scheme: ios/RCTWeChat 36 | script: 37 | - cd ios 38 | - xcodebuild -scheme RCTWeChat -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-wechat", 3 | "version": "1.10.0", 4 | "description": "react-native library for wechat app", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+ssh://git@github.com/weflex/react-native-wechat.git" 12 | }, 13 | "keywords": [ 14 | "wechat", 15 | "react", 16 | "react-native", 17 | "react-component", 18 | "ios" 19 | ], 20 | "dependencies": { 21 | "events": "1.0.2" 22 | }, 23 | "peerDependencies": { 24 | "react-native": ">=0.40" 25 | }, 26 | "author": "Yorkie Liu ", 27 | "contributors": [ 28 | { 29 | "name": "Yorkie Liu", 30 | "email": "yorkiefixer@gmail.com" 31 | }, 32 | { 33 | "name": "Deng Yun", 34 | "email": "tdzl2003@gmail.com" 35 | } 36 | ], 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/weflex/react-native-wechat/issues" 40 | }, 41 | "homepage": "https://github.com/weflex/react-native-wechat#readme" 42 | } 43 | -------------------------------------------------------------------------------- /ios/RCTWeChatTests/RCTWeChatTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // RCTWeChatTests.m 3 | // RCTWeChatTests 4 | // 5 | // Created by Yorkie on 12/07/2017. 6 | // Copyright © 2017 WeFlex. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RCTWeChatTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation RCTWeChatTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Yazhong Liu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /android/src/main/java/com/theweflex/react/WeChatPackage.java: -------------------------------------------------------------------------------- 1 | package com.theweflex.react; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.Arrays; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | /** 14 | * Created by tdzl2_000 on 2015-10-10. 15 | */ 16 | public class WeChatPackage implements ReactPackage { 17 | @Override 18 | public List createNativeModules(ReactApplicationContext reactContext) { 19 | return Arrays.asList(new NativeModule[]{ 20 | // Modules from third-party 21 | new WeChatModule(reactContext), 22 | }); 23 | } 24 | 25 | public List> createJSModules() { 26 | return Collections.emptyList(); 27 | } 28 | 29 | @Override 30 | public List createViewManagers(ReactApplicationContext reactContext) { 31 | return Collections.emptyList(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ios/RCTWeChat.h: -------------------------------------------------------------------------------- 1 | // 2 | // RCTWeChat.h 3 | // RCTWeChat 4 | // 5 | // Created by Yorkie Liu on 10/16/15. 6 | // Copyright © 2015 WeFlex. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #import 13 | #import "WXApi.h" 14 | 15 | // define share type constants 16 | #define RCTWXShareTypeNews @"news" 17 | #define RCTWXShareTypeThumbImageUrl @"thumbImage" 18 | #define RCTWXShareTypeImageUrl @"imageUrl" 19 | #define RCTWXShareTypeImageFile @"imageFile" 20 | #define RCTWXShareTypeImageResource @"imageResource" 21 | #define RCTWXShareTypeText @"text" 22 | #define RCTWXShareTypeVideo @"video" 23 | #define RCTWXShareTypeAudio @"audio" 24 | #define RCTWXShareTypeFile @"file" 25 | #define RCTWXShareTypeMini @"mini" 26 | 27 | #define RCTWXShareType @"type" 28 | #define RCTWXShareTitle @"title" 29 | #define RCTWXShareDescription @"description" 30 | #define RCTWXShareWebpageUrl @"webpageUrl" 31 | #define RCTWXShareImageUrl @"imageUrl" 32 | 33 | #define RCTWXEventName @"WeChat_Resp" 34 | 35 | @interface RCTWeChat : NSObject 36 | 37 | @property NSString* appId; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/xcuserdata/yorkie.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RCTWeChat.xcscheme_^#shared#^_ 8 | 9 | isShown 10 | 11 | orderHint 12 | 0 13 | 14 | RCTWeChatTests.xcscheme_^#shared#^_ 15 | 16 | isShown 17 | 18 | orderHint 19 | 1 20 | 21 | 22 | SuppressBuildableAutocreation 23 | 24 | 10D6D7881F160B720066F0F3 25 | 26 | primary 27 | 28 | 29 | 10D6D7951F160C0B0066F0F3 30 | 31 | primary 32 | 33 | 34 | 10D6D7A31F160C250066F0F3 35 | 36 | primary 37 | 38 | 39 | 86D238411BD0BB9E00C75D01 40 | 41 | primary 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Example/index.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | */ 5 | 'use strict'; 6 | 7 | var React = require('react-native'); 8 | var { 9 | AppRegistry, 10 | StyleSheet, 11 | Text, 12 | View, 13 | } = React; 14 | 15 | var Example = React.createClass({ 16 | render: function() { 17 | return ( 18 | 19 | 20 | Welcome to React Native! 21 | 22 | 23 | To get started, edit index.android.js 24 | 25 | 26 | Shake or press menu button for dev menu 27 | 28 | 29 | ); 30 | } 31 | }); 32 | 33 | var styles = StyleSheet.create({ 34 | container: { 35 | flex: 1, 36 | justifyContent: 'center', 37 | alignItems: 'center', 38 | backgroundColor: '#F5FCFF', 39 | }, 40 | welcome: { 41 | fontSize: 20, 42 | textAlign: 'center', 43 | margin: 10, 44 | }, 45 | instructions: { 46 | textAlign: 'center', 47 | color: '#333333', 48 | marginBottom: 5, 49 | }, 50 | }); 51 | 52 | AppRegistry.registerComponent('Example', () => Example); 53 | -------------------------------------------------------------------------------- /react-native-wechat.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint react-native-qq.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = "react-native-wechat" 11 | s.version = "1.9.10" 12 | s.summary = "React-Native(iOS/Android) functionalities include WeChat Login, Share, Favorite and Payment {QQ: 336021910}" 13 | s.description = <<-DESC 14 | React-Native(iOS/Android) functionalities include WeChat Login, Share, Favorite and Payment {QQ: 336021910} 15 | DESC 16 | s.author = { "weflex" => "336021910@qq.com" } 17 | s.homepage = "https://github.com/weflex/react-native-wechat" 18 | s.license = "MIT" 19 | s.platform = :ios, "9.0" 20 | s.source = { :git => "https://github.com/weflex/react-native-wechat.git", :tag => "master" } 21 | s.source_files = "ios/*.{h,m}" 22 | s.dependency "React" 23 | s.vendored_libraries = "ios/libWeChatSDK.a" 24 | s.requires_arc = true 25 | s.frameworks = 'SystemConfiguration','CoreTelephony' 26 | s.library = 'sqlite3','c++','z' 27 | end 28 | -------------------------------------------------------------------------------- /Example/ios/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | NSLocationWhenInUseUsageDescription 31 | 32 | UILaunchStoryboardName 33 | LaunchScreen 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /docs/build-setup-ios.md: -------------------------------------------------------------------------------- 1 | # Build Setup for iOS 2 | 3 | Add the following libraries to your "Link Binary with Libraries": 4 | 5 | - [x] `SystemConfiguration.framework` 6 | - [x] `CoreTelephony.framework` 7 | - [x] `libsqlite3.0` 8 | - [x] `libc++` 9 | - [x] `libz` 10 | 11 | Add "URL Schema" as your app id for "URL type" in Targets > info, See 12 | the following screenshot for the view on your XCode: 13 | 14 | ![Set URL Schema in XCode](https://res.wx.qq.com/open/zh_CN/htmledition/res/img/pic/app-access-guide/ios/image0042168b9.jpg) 15 | 16 | On iOS 9+, add `wechat` and `weixin` into `LSApplicationQueriesSchemes` in 17 | `Targets` > `info` > `Custom iOS Target Properties`. Or edit `Info.plist` 18 | then add: 19 | 20 | ```xml 21 | LSApplicationQueriesSchemes 22 | 23 | weixin 24 | wechat 25 | 26 | ``` 27 | 28 | Then copy the following in `AppDelegate.m`: 29 | 30 | ```objc 31 | #import 32 | 33 | // ios 8.x or older 34 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 35 | sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 36 | { 37 | return [RCTLinkingManager application:application openURL:url 38 | sourceApplication:sourceApplication annotation:annotation]; 39 | } 40 | 41 | // ios 9.0+ 42 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 43 | options:(NSDictionary *)options 44 | { 45 | return [RCTLinkingManager application:application openURL:url options:options]; 46 | } 47 | 48 | 49 | ``` 50 | -------------------------------------------------------------------------------- /Example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*.web.js 5 | .*/*.android.js 6 | 7 | # Some modules have their own node_modules with overlap 8 | .*/node_modules/node-haste/.* 9 | 10 | # Ignore react-tools where there are overlaps, but don't ignore anything that 11 | # react-native relies on 12 | .*/node_modules/react-tools/src/React.js 13 | .*/node_modules/react-tools/src/renderers/shared/event/EventPropagators.js 14 | .*/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js 15 | .*/node_modules/react-tools/src/shared/vendor/core/ExecutionEnvironment.js 16 | 17 | # Ignore commoner tests 18 | .*/node_modules/commoner/test/.* 19 | 20 | # See https://github.com/facebook/flow/issues/442 21 | .*/react-tools/node_modules/commoner/lib/reader.js 22 | 23 | # Ignore jest 24 | .*/node_modules/jest-cli/.* 25 | 26 | # Ignore Website 27 | .*/website/.* 28 | 29 | [include] 30 | 31 | [libs] 32 | node_modules/react-native/Libraries/react-native/react-native-interface.js 33 | 34 | [options] 35 | module.system=haste 36 | 37 | munge_underscores=true 38 | 39 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' 40 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub' 41 | 42 | suppress_type=$FlowIssue 43 | suppress_type=$FlowFixMe 44 | suppress_type=$FixMe 45 | 46 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-7]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 47 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-7]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+ 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 49 | 50 | [version] 51 | 0.17.0 52 | -------------------------------------------------------------------------------- /ios/WechatAuthSDK.h: -------------------------------------------------------------------------------- 1 | // 2 | // WechatAuthSDK.h 3 | // WechatAuthSDK 4 | // 5 | // Created by 李凯 on 13-11-29. 6 | // Copyright (c) 2013年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | enum AuthErrCode { 13 | WechatAuth_Err_Ok = 0, //Auth成功 14 | WechatAuth_Err_NormalErr = -1, //普通错误 15 | WechatAuth_Err_NetworkErr = -2, //网络错误 16 | WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败 17 | WechatAuth_Err_Cancel = -4, //用户取消授权 18 | WechatAuth_Err_Timeout = -5, //超时 19 | }; 20 | 21 | @protocol WechatAuthAPIDelegate 22 | @optional 23 | 24 | - (void)onAuthGotQrcode:(UIImage *)image; //得到二维码 25 | - (void)onQrcodeScanned; //二维码被扫描 26 | - (void)onAuthFinish:(int)errCode AuthCode:(NSString *)authCode; //成功登录 27 | 28 | @end 29 | 30 | @interface WechatAuthSDK : NSObject{ 31 | NSString *_sdkVersion; 32 | __weak id _delegate; 33 | } 34 | 35 | @property(nonatomic, weak) id delegate; 36 | @property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号 37 | 38 | /*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调 39 | * 40 | * @param appId 微信开发者ID 41 | * @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同 42 | * @param timeStamp 时间戳 43 | * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔 44 | * @param signature 签名 45 | * @param schemeData 会在扫码后拼在scheme后 46 | * @return 成功返回YES,失败返回NO 47 | 注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。 48 | */ 49 | 50 | - (BOOL)Auth:(NSString *)appId 51 | nonceStr:(NSString *)nonceStr 52 | timeStamp:(NSString*)timeStamp 53 | scope:(NSString *)scope 54 | signature:(NSString *)signature 55 | schemeData:(NSString *)schemeData; 56 | 57 | 58 | /*! @brief 暂停登录请求 59 | * 60 | * @return 成功返回YES,失败返回NO。 61 | */ 62 | - (BOOL)StopAuth; 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /ios/RCTWeChat.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint RCTPili.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = "RCTWeChat" 11 | s.version = "0.1.0" 12 | s.summary = "React-Native(iOS/Android) functionalities include WeChat Login, Share, Favorite and Payment {QQ: 336021910}" 13 | 14 | # This description is used to generate tags and improve search results. 15 | # * Think: What does it do? Why did you write it? What is the focus? 16 | # * Try to keep it short, snappy and to the point. 17 | # * Write the description between the DESC delimiters below. 18 | # * Finally, don't worry about the indent, CocoaPods strips it! 19 | s.description = <<-DESC 20 | React-Native(iOS/Android) functionalities include WeChat Login, Share, Favorite and Payment {QQ: 336021910} 21 | DESC 22 | 23 | s.homepage = "https://github.com/weflex/react-native-wechat" 24 | s.license = "MIT" 25 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 26 | s.author = { "weflex" => "336021910@qq.com" } 27 | s.platform = :ios, "7.0" 28 | s.source = { :git => "https://github.com/weflex/react-native-wechat.git", :tag => "master" } 29 | s.source_files = "**/*.{h,m}" 30 | s.requires_arc = true 31 | 32 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 33 | s.dependency "React" 34 | s.vendored_libraries = "libWeChatSDK.a" 35 | s.ios.frameworks = 'SystemConfiguration','CoreTelephony','XCTest' 36 | s.ios.library = 'sqlite3','c++','z' 37 | 38 | end 39 | -------------------------------------------------------------------------------- /Example/ios/Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import "RCTRootView.h" 13 | 14 | @implementation AppDelegate 15 | 16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 17 | { 18 | NSURL *jsCodeLocation; 19 | 20 | /** 21 | * Loading JavaScript code - uncomment the one you want. 22 | * 23 | * OPTION 1 24 | * Load from development server. Start the server from the repository root: 25 | * 26 | * $ npm start 27 | * 28 | * To run on device, change `localhost` to the IP address of your computer 29 | * (you can get this by typing `ifconfig` into the terminal and selecting the 30 | * `inet` value under `en0:`) and make sure your computer and iOS device are 31 | * on the same Wi-Fi network. 32 | */ 33 | 34 | jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; 35 | 36 | /** 37 | * OPTION 2 38 | * Load from pre-bundled file on disk. The static bundle is automatically 39 | * generated by "Bundle React Native code and images" build step. 40 | */ 41 | 42 | // jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 43 | 44 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 45 | moduleName:@"Example" 46 | initialProperties:nil 47 | launchOptions:launchOptions]; 48 | 49 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 50 | UIViewController *rootViewController = [[UIViewController alloc] init]; 51 | rootViewController.view = rootView; 52 | self.window.rootViewController = rootViewController; 53 | [self.window makeKeyAndVisible]; 54 | return YES; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | 30 | # Do not strip any method/class that is annotated with @DoNotStrip 31 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 32 | -keepclassmembers class * { 33 | @com.facebook.proguard.annotations.DoNotStrip *; 34 | } 35 | 36 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 37 | void set*(***); 38 | *** get*(); 39 | } 40 | 41 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 42 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 43 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 44 | -keepclassmembers class * { @com.facebook.react.uimanager.ReactProp ; } 45 | -keepclassmembers class * { @com.facebook.react.uimanager.ReactPropGroup ; } 46 | 47 | # okhttp 48 | 49 | -keepattributes Signature 50 | -keepattributes *Annotation* 51 | -keep class com.squareup.okhttp.** { *; } 52 | -keep interface com.squareup.okhttp.** { *; } 53 | -dontwarn com.squareup.okhttp.** 54 | 55 | # okio 56 | 57 | -keep class sun.misc.Unsafe { *; } 58 | -dontwarn java.nio.file.* 59 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 60 | -dontwarn okio.** 61 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.KeyEvent; 6 | 7 | import com.facebook.react.LifecycleState; 8 | import com.facebook.react.ReactInstanceManager; 9 | import com.facebook.react.ReactRootView; 10 | import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; 11 | import com.facebook.react.shell.MainReactPackage; 12 | import com.facebook.soloader.SoLoader; 13 | 14 | public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { 15 | 16 | private ReactInstanceManager mReactInstanceManager; 17 | private ReactRootView mReactRootView; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | mReactRootView = new ReactRootView(this); 23 | 24 | mReactInstanceManager = ReactInstanceManager.builder() 25 | .setApplication(getApplication()) 26 | .setBundleAssetName("index.android.bundle") 27 | .setJSMainModuleName("index.android") 28 | .addPackage(new MainReactPackage()) 29 | .setUseDeveloperSupport(BuildConfig.DEBUG) 30 | .setInitialLifecycleState(LifecycleState.RESUMED) 31 | .build(); 32 | 33 | mReactRootView.startReactApplication(mReactInstanceManager, "Example", null); 34 | 35 | setContentView(mReactRootView); 36 | } 37 | 38 | @Override 39 | public boolean onKeyUp(int keyCode, KeyEvent event) { 40 | if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) { 41 | mReactInstanceManager.showDevOptionsDialog(); 42 | return true; 43 | } 44 | return super.onKeyUp(keyCode, event); 45 | } 46 | 47 | @Override 48 | public void onBackPressed() { 49 | if (mReactInstanceManager != null) { 50 | mReactInstanceManager.onBackPressed(); 51 | } else { 52 | super.onBackPressed(); 53 | } 54 | } 55 | 56 | @Override 57 | public void invokeDefaultOnBackPressed() { 58 | super.onBackPressed(); 59 | } 60 | 61 | @Override 62 | protected void onPause() { 63 | super.onPause(); 64 | 65 | if (mReactInstanceManager != null) { 66 | mReactInstanceManager.onPause(); 67 | } 68 | } 69 | 70 | @Override 71 | protected void onResume() { 72 | super.onResume(); 73 | 74 | if (mReactInstanceManager != null) { 75 | mReactInstanceManager.onResume(this); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /docs/build-setup-android.md: -------------------------------------------------------------------------------- 1 | # Build Setup for Android 2 | 3 | Copy lines to `android/settings.gradle`: 4 | 5 | ```gradle 6 | include ':RCTWeChat' 7 | project(':RCTWeChat').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wechat/android') 8 | ``` 9 | 10 | Copy lines to `android/app/build.gradle` 11 | 12 | ```gradle 13 | dependencies { 14 | compile project(':RCTWeChat') 15 | } 16 | ``` 17 | 18 | Copy lines to `proguard-rules.pro`: 19 | 20 | ```pro 21 | -keep class com.tencent.mm.sdk.** { 22 | *; 23 | } 24 | ``` 25 | 26 | Then update `MainActivity.java` or `MainApplication.java`: 27 | 28 | ```java 29 | import com.theweflex.react.WeChatPackage; 30 | 31 | @Override 32 | protected List getPackages() { 33 | return Arrays.asList( 34 | new MainReactPackage(), 35 | new WeChatPackage() // Add this line 36 | ); 37 | } 38 | ``` 39 | 40 | **Integrating with login and share** 41 | 42 | If you are going to integrate login or share functions, you need to 43 | create a package named 'wxapi' in your application package and a class 44 | named `WXEntryActivity` in it. 45 | 46 | ```java 47 | package your.package.wxapi; 48 | 49 | import android.app.Activity; 50 | import android.os.Bundle; 51 | import com.theweflex.react.WeChatModule; 52 | 53 | public class WXEntryActivity extends Activity { 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | WeChatModule.handleIntent(getIntent()); 58 | finish(); 59 | } 60 | } 61 | ``` 62 | 63 | Then add the following node to `AndroidManifest.xml`: 64 | 65 | ```xml 66 | 67 | 68 | 73 | 74 | 75 | ``` 76 | 77 | **Integrating the WeChat Payment** 78 | 79 | If you are going to integrate payment functionality by using this library, then 80 | create a package named also `wxapi` in your application package and a class named 81 | `WXPayEntryActivity`, this is used to bypass the response to JS level: 82 | 83 | ```java 84 | package your.package.wxapi; 85 | 86 | import android.app.Activity; 87 | import android.os.Bundle; 88 | import com.theweflex.react.WeChatModule; 89 | 90 | public class WXPayEntryActivity extends Activity { 91 | @Override 92 | protected void onCreate(Bundle savedInstanceState) { 93 | super.onCreate(savedInstanceState); 94 | WeChatModule.handleIntent(getIntent()); 95 | finish(); 96 | } 97 | } 98 | ``` 99 | 100 | Then add the following node to `AndroidManifest.xml`: 101 | 102 | ```xml 103 | 104 | 105 | 110 | 111 | 112 | ``` 113 | -------------------------------------------------------------------------------- /Example/index.ios.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | */ 5 | "use strict"; 6 | 7 | var React = require('react-native'); 8 | var { 9 | AppRegistry, 10 | StyleSheet, 11 | Text, 12 | View, 13 | TouchableOpacity 14 | } = React; 15 | var WeChat = require('./react-native-wechat.js'); 16 | 17 | class Example extends React.Component { 18 | constructor(props) { 19 | super(props); 20 | this.state = { 21 | apiVersion: 'waiting...', 22 | wxAppInstallUrl: 'waiting...', 23 | isWXAppSupportApi: 'waiting...', 24 | isWXAppInstalled: 'waiting...', 25 | }; 26 | } 27 | async componentDidMount() { 28 | try { 29 | await WeChat.registerApp('1234567'); 30 | this.setState({ 31 | apiVersion: await WeChat.getApiVersion(), 32 | wxAppInstallUrl: await WeChat.getWXAppInstallUrl(), 33 | isWXAppSupportApi: await WeChat.isWXAppSupportApi(), 34 | isWXAppInstalled: await WeChat.isWXAppInstalled() 35 | }); 36 | console.log(this.state); 37 | } catch (e) { 38 | console.error(e); 39 | } 40 | console.log(WeChat); 41 | // console.log('getApiVersion', typeof WeChat.getApiVersion); 42 | // console.log('getWXAppInstallUrl', typeof WeChat.getWXAppInstallUrl); 43 | // console.log('sendRequest', typeof WeChat.sendRequest); 44 | // console.log('registerApp', typeof WeChat.registerApp); 45 | // console.log('sendErrorCommonResponse', typeof WeChat.sendErrorCommonResponse); 46 | // console.log('sendErrorUserCancelResponse', typeof WeChat.sendErrorUserCancelResponse); 47 | // console.log('sendAuthRequest', typeof WeChat.sendAuthRequest); 48 | // console.log('getWXAppInstallUrl', typeof WeChat.getWXAppInstallUrl); 49 | // console.log('openWXApp', typeof WeChat.openWXApp); 50 | // console.log('registerAppWithDescription', typeof WeChat.registerAppWithDescription); 51 | // console.log('isWXAppSupportApi', typeof WeChat.isWXAppSupportApi); 52 | // console.log('isWXAppInstalled', typeof WeChat.isWXAppInstalled); 53 | } 54 | render() { 55 | return ( 56 | 57 | api版本:{this.state.apiVersion} 58 | 微信注册url:{this.state.wxAppInstallUrl} 59 | 是否支持api:{String(this.state.isWXAppSupportApi)} 60 | 是否安装微信:{String(this.state.isWXAppInstalled)} 61 | 62 | 打开微信 63 | 64 | 65 | ); 66 | } 67 | async _openWXApp() { 68 | await WeChat.openWXApp(); 69 | } 70 | } 71 | 72 | var styles = StyleSheet.create({ 73 | container: { 74 | flex: 1, 75 | justifyContent: 'center', 76 | alignItems: 'center', 77 | backgroundColor: '#F5FCFF', 78 | }, 79 | welcome: { 80 | fontSize: 20, 81 | textAlign: 'center', 82 | margin: 10, 83 | }, 84 | instructions: { 85 | textAlign: 'center', 86 | color: '#333333', 87 | marginBottom: 5, 88 | }, 89 | }); 90 | 91 | AppRegistry.registerComponent('Example', () => Example); 92 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/xcuserdata/yorkieliu.xcuserdatad/xcschemes/RCTWeChat.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | /** 4 | * The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets. 5 | * These basically call `react-native bundle` with the correct arguments during the Android build 6 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 7 | * bundle directly from the development server. Below you can see all the possible configurations 8 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 9 | * `apply from: "react.gradle"` line. 10 | * 11 | * project.ext.react = [ 12 | * // the name of the generated asset file containing your JS bundle 13 | * bundleAssetName: "index.android.bundle", 14 | * 15 | * // the entry file for bundle generation 16 | * entryFile: "index.android.js", 17 | * 18 | * // whether to bundle JS and assets in debug mode 19 | * bundleInDebug: false, 20 | * 21 | * // whether to bundle JS and assets in release mode 22 | * bundleInRelease: true, 23 | * 24 | * // the root of your project, i.e. where "package.json" lives 25 | * root: "../../", 26 | * 27 | * // where to put the JS bundle asset in debug mode 28 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 29 | * 30 | * // where to put the JS bundle asset in release mode 31 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 32 | * 33 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 34 | * // require('./image.png')), in debug mode 35 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 36 | * 37 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 38 | * // require('./image.png')), in release mode 39 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 40 | * 41 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 42 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 43 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 44 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 45 | * // for example, you might want to remove it from here. 46 | * inputExcludes: ["android/**", "ios/**"] 47 | * ] 48 | */ 49 | 50 | apply from: "react.gradle" 51 | 52 | android { 53 | compileSdkVersion 23 54 | buildToolsVersion "23.0.1" 55 | 56 | defaultConfig { 57 | applicationId "com.example" 58 | minSdkVersion 16 59 | targetSdkVersion 22 60 | versionCode 1 61 | versionName "1.0" 62 | ndk { 63 | abiFilters "armeabi-v7a", "x86" 64 | } 65 | } 66 | buildTypes { 67 | release { 68 | minifyEnabled false // Set this to true to enable Proguard 69 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 70 | } 71 | } 72 | } 73 | 74 | dependencies { 75 | compile fileTree(dir: "libs", include: ["*.jar"]) 76 | compile "com.android.support:appcompat-v7:23.0.1" 77 | compile "com.facebook.react:react-native:0.14.+" 78 | } 79 | -------------------------------------------------------------------------------- /Example/android/app/react.gradle: -------------------------------------------------------------------------------- 1 | def config = project.hasProperty("react") ? project.react : []; 2 | 3 | def bundleAssetName = config.bundleAssetName ?: "index.android.bundle" 4 | def entryFile = config.entryFile ?: "index.android.js" 5 | 6 | // because elvis operator 7 | def elvisFile(thing) { 8 | return thing ? file(thing) : null; 9 | } 10 | 11 | def reactRoot = elvisFile(config.root) ?: file("../../") 12 | def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?: 13 | file("$buildDir/intermediates/assets/debug") 14 | def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?: 15 | file("$buildDir/intermediates/assets/release") 16 | def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?: 17 | file("$buildDir/intermediates/res/merged/debug") 18 | def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?: 19 | file("$buildDir/intermediates/res/merged/release") 20 | def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"] 21 | 22 | def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName") 23 | def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName") 24 | 25 | task bundleDebugJsAndAssets(type: Exec) { 26 | // create dirs if they are not there (e.g. the "clean" task just ran) 27 | doFirst { 28 | jsBundleDirDebug.mkdirs() 29 | resourcesDirDebug.mkdirs() 30 | } 31 | 32 | // set up inputs and outputs so gradle can cache the result 33 | inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) 34 | outputs.dir jsBundleDirDebug 35 | outputs.dir resourcesDirDebug 36 | 37 | // set up the call to the react-native cli 38 | workingDir reactRoot 39 | commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", 40 | entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug 41 | 42 | enabled config.bundleInDebug ?: false 43 | } 44 | 45 | task bundleReleaseJsAndAssets(type: Exec) { 46 | // create dirs if they are not there (e.g. the "clean" task just ran) 47 | doFirst { 48 | jsBundleDirRelease.mkdirs() 49 | resourcesDirRelease.mkdirs() 50 | } 51 | 52 | // set up inputs and outputs so gradle can cache the result 53 | inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) 54 | outputs.dir jsBundleDirRelease 55 | outputs.dir resourcesDirRelease 56 | 57 | // set up the call to the react-native cli 58 | workingDir reactRoot 59 | commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file", 60 | entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease 61 | 62 | enabled config.bundleInRelease ?: true 63 | } 64 | 65 | gradle.projectsEvaluated { 66 | // hook bundleDebugJsAndAssets into the android build process 67 | bundleDebugJsAndAssets.dependsOn mergeDebugResources 68 | bundleDebugJsAndAssets.dependsOn mergeDebugAssets 69 | processDebugResources.dependsOn bundleDebugJsAndAssets 70 | 71 | // hook bundleReleaseJsAndAssets into the android build process 72 | bundleReleaseJsAndAssets.dependsOn mergeReleaseResources 73 | bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets 74 | processReleaseResources.dependsOn bundleReleaseJsAndAssets 75 | } 76 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at yorkiefixer@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/xcshareddata/xcschemes/RCTWeChat.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 55 | 61 | 62 | 63 | 64 | 65 | 66 | 72 | 73 | 79 | 80 | 81 | 82 | 84 | 85 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /Example/ios/Example/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 22 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/xcshareddata/xcschemes/RCTWeChatTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 78 | 79 | 80 | 81 | 82 | 83 | 89 | 90 | 96 | 97 | 98 | 99 | 101 | 102 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 78 | 80 | 86 | 87 | 88 | 89 | 90 | 91 | 97 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /ios/WXApi.h: -------------------------------------------------------------------------------- 1 | // 2 | // WXApi.h 3 | // 所有Api接口 4 | // 5 | // Created by Wechat on 12-2-28. 6 | // Copyright (c) 2012年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WXApiObject.h" 11 | 12 | 13 | #pragma mark - WXApiDelegate 14 | /*! @brief 接收并处理来自微信终端程序的事件消息 15 | * 16 | * 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。 17 | * WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。 18 | */ 19 | @protocol WXApiDelegate 20 | @optional 21 | 22 | /*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果 23 | * 24 | * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 25 | * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 26 | * @param req 具体请求内容,是自动释放的 27 | */ 28 | -(void) onReq:(BaseReq*)req; 29 | 30 | 31 | 32 | /*! @brief 发送一个sendReq后,收到微信的回应 33 | * 34 | * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 35 | * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 36 | * @param resp具体的回应内容,是自动释放的 37 | */ 38 | -(void) onResp:(BaseResp*)resp; 39 | 40 | @end 41 | 42 | #pragma mark - WXApiLogDelegate 43 | 44 | @protocol WXApiLogDelegate 45 | 46 | -(void) onLog:(NSString*)log logLevel:(WXLogLevel)level; 47 | 48 | @end 49 | 50 | #pragma mark - WXApi 51 | 52 | /*! @brief 微信Api接口函数类 53 | * 54 | * 该类封装了微信终端SDK的所有接口 55 | */ 56 | @interface WXApi : NSObject 57 | 58 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 59 | * 60 | * 需要在每次启动第三方应用程序时调用。第一次调用后,会在微信的可用应用列表中出现,默认开启MTA数据上报。 61 | * iOS7及以上系统需要调起一次微信才会出现在微信的可用应用列表中。 62 | * @attention 请保证在主线程中调用此函数 63 | * @param appid 微信开发者ID 64 | * @param typeFlag 应用支持打开的文件类型 65 | * @return 成功返回YES,失败返回NO。 66 | */ 67 | +(BOOL) registerApp:(NSString *)appid; 68 | 69 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 70 | * 71 | * 需要在每次启动第三方应用程序时调用。第一次调用后,会在微信的可用应用列表中出现。 72 | * iOS7及以上系统需要调起一次微信才会出现在微信的可用应用列表中。 73 | * @attention 请保证在主线程中调用此函数 74 | * @param appid 微信开发者ID 75 | * @param isEnableMTA 是否支持MTA数据上报 76 | * @return 成功返回YES,失败返回NO。 77 | */ 78 | +(BOOL) registerApp:(NSString *)appid enableMTA:(BOOL)isEnableMTA; 79 | 80 | 81 | /*! @brief WXApi的成员函数,向微信终端程序注册应用支持打开的文件类型。 82 | * 83 | * 需要在每次启动第三方应用程序时调用。调用后并第一次成功分享数据到微信后,会在微信的可用应用列表中出现。 84 | * @see registerApp 85 | * @param typeFlag 应用支持打开的数据类型, enAppSupportContentFlag枚举类型 “|” 操作后结果 86 | */ 87 | +(void) registerAppSupportContentFlag:(UInt64)typeFlag; 88 | 89 | 90 | 91 | /*! @brief 处理微信通过URL启动App时传递的数据 92 | * 93 | * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 94 | * @param url 微信启动第三方应用时传递过来的URL 95 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 96 | * @return 成功返回YES,失败返回NO。 97 | */ 98 | +(BOOL) handleOpenURL:(NSURL *) url delegate:(id) delegate; 99 | 100 | 101 | 102 | /*! @brief 检查微信是否已被用户安装 103 | * 104 | * @return 微信已安装返回YES,未安装返回NO。 105 | */ 106 | +(BOOL) isWXAppInstalled; 107 | 108 | 109 | 110 | /*! @brief 判断当前微信的版本是否支持OpenApi 111 | * 112 | * @return 支持返回YES,不支持返回NO。 113 | */ 114 | +(BOOL) isWXAppSupportApi; 115 | 116 | 117 | 118 | /*! @brief 获取微信的itunes安装地址 119 | * 120 | * @return 微信的安装地址字符串。 121 | */ 122 | +(NSString *) getWXAppInstallUrl; 123 | 124 | 125 | 126 | /*! @brief 获取当前微信SDK的版本号 127 | * 128 | * @return 返回当前微信SDK的版本号 129 | */ 130 | +(NSString *) getApiVersion; 131 | 132 | 133 | 134 | /*! @brief 打开微信 135 | * 136 | * @return 成功返回YES,失败返回NO。 137 | */ 138 | +(BOOL) openWXApp; 139 | 140 | 141 | 142 | /*! @brief 发送请求到微信,等待微信返回onResp 143 | * 144 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型 145 | * SendAuthReq、SendMessageToWXReq、PayReq等。 146 | * @param req 具体的发送请求,在调用函数后,请自己释放。 147 | * @return 成功返回YES,失败返回NO。 148 | */ 149 | +(BOOL) sendReq:(BaseReq*)req; 150 | 151 | /*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp 152 | * 153 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。 154 | * @param req 具体的发送请求,在调用函数后,请自己释放。 155 | * @param viewController 当前界面对象。 156 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 157 | * @return 成功返回YES,失败返回NO。 158 | */ 159 | +(BOOL) sendAuthReq:(SendAuthReq*)req viewController:(UIViewController*)viewController delegate:(id)delegate; 160 | 161 | 162 | /*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面 163 | * 164 | * 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有 165 | * GetMessageFromWXResp、ShowMessageFromWXResp等。 166 | * @param resp 具体的应答内容,调用函数后,请自己释放 167 | * @return 成功返回YES,失败返回NO。 168 | */ 169 | +(BOOL) sendResp:(BaseResp*)resp; 170 | 171 | 172 | /*! @brief WXApi的成员函数,接受微信的log信息。byBlock 173 | 注意1:SDK会强引用这个block,注意不要导致内存泄漏,注意不要导致内存泄漏 174 | 注意2:调用过一次startLog by block之后,如果再调用一次任意方式的startLoad,会释放上一次logBlock,不再回调上一个logBlock 175 | * 176 | * @param level 打印log的级别 177 | * @param logBlock 打印log的回调block 178 | */ 179 | +(void) startLogByLevel:(WXLogLevel)level logBlock:(WXLogBolock)logBlock; 180 | 181 | /*! @brief WXApi的成员函数,接受微信的log信息。byDelegate 182 | 注意1:sdk会弱引用这个delegate,这里可加任意对象为代理,不需要与WXApiDelegate同一个对象 183 | 注意2:调用过一次startLog by delegate之后,再调用一次任意方式的startLoad,不会再回调上一个logDelegate对象 184 | * @param level 打印log的级别 185 | * @param logDelegate 打印log的回调代理, 186 | */ 187 | + (void)startLogByLevel:(WXLogLevel)level logDelegate:(id)logDelegate; 188 | 189 | /*! @brief 停止打印log,会清理block或者delegate为空,释放block 190 | * @param 191 | */ 192 | + (void)stopLog; 193 | @end 194 | -------------------------------------------------------------------------------- /Example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /android/react-native-wechat.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import {DeviceEventEmitter, NativeModules, Platform} from 'react-native'; 4 | import {EventEmitter} from 'events'; 5 | 6 | let isAppRegistered = false; 7 | const {WeChat} = NativeModules; 8 | 9 | // Event emitter to dispatch request and response from WeChat. 10 | const emitter = new EventEmitter(); 11 | 12 | DeviceEventEmitter.addListener('WeChat_Resp', resp => { 13 | emitter.emit(resp.type, resp); 14 | }); 15 | 16 | function wrapRegisterApp(nativeFunc) { 17 | if (!nativeFunc) { 18 | return undefined; 19 | } 20 | return (...args) => { 21 | if (isAppRegistered) { 22 | // FIXME(Yorkie): we ignore this error if AppRegistered is true. 23 | return Promise.resolve(true); 24 | } 25 | isAppRegistered = true; 26 | return new Promise((resolve, reject) => { 27 | nativeFunc.apply(null, [ 28 | ...args, 29 | (error, result) => { 30 | if (!error) { 31 | return resolve(result); 32 | } 33 | if (typeof error === 'string') { 34 | return reject(new Error(error)); 35 | } 36 | reject(error); 37 | }, 38 | ]); 39 | }); 40 | }; 41 | } 42 | 43 | function wrapApi(nativeFunc) { 44 | if (!nativeFunc) { 45 | return undefined; 46 | } 47 | return (...args) => { 48 | if (!isAppRegistered) { 49 | return Promise.reject(new Error('registerApp required.')); 50 | } 51 | return new Promise((resolve, reject) => { 52 | nativeFunc.apply(null, [ 53 | ...args, 54 | (error, result) => { 55 | if (!error) { 56 | return resolve(result); 57 | } 58 | if (typeof error === 'string') { 59 | return reject(new Error(error)); 60 | } 61 | reject(error); 62 | }, 63 | ]); 64 | }); 65 | }; 66 | } 67 | 68 | /** 69 | * `addListener` inherits from `events` module 70 | * @method addListener 71 | * @param {String} eventName - the event name 72 | * @param {Function} trigger - the function when event is fired 73 | */ 74 | export const addListener = emitter.addListener.bind(emitter); 75 | 76 | /** 77 | * `once` inherits from `events` module 78 | * @method once 79 | * @param {String} eventName - the event name 80 | * @param {Function} trigger - the function when event is fired 81 | */ 82 | export const once = emitter.once.bind(emitter); 83 | 84 | /** 85 | * `removeAllListeners` inherits from `events` module 86 | * @method removeAllListeners 87 | * @param {String} eventName - the event name 88 | */ 89 | export const removeAllListeners = emitter.removeAllListeners.bind(emitter); 90 | 91 | /** 92 | * @method registerApp 93 | * @param {String} appid - the app id 94 | * @return {Promise} 95 | */ 96 | export const registerApp = wrapRegisterApp(WeChat.registerApp); 97 | 98 | /** 99 | * @method registerAppWithDescription 100 | * @param {String} appid - the app id 101 | * @param {String} appdesc - the app description 102 | * @return {Promise} 103 | */ 104 | export const registerAppWithDescription = wrapRegisterApp( 105 | WeChat.registerAppWithDescription, 106 | ); 107 | 108 | /** 109 | * Return if the wechat app is installed in the device. 110 | * @method isWXAppInstalled 111 | * @return {Promise} 112 | */ 113 | export const isWXAppInstalled = wrapApi(WeChat.isWXAppInstalled); 114 | 115 | /** 116 | * Return if the wechat application supports the api 117 | * @method isWXAppSupportApi 118 | * @return {Promise} 119 | */ 120 | export const isWXAppSupportApi = wrapApi(WeChat.isWXAppSupportApi); 121 | 122 | /** 123 | * Get the wechat app installed url 124 | * @method getWXAppInstallUrl 125 | * @return {String} the wechat app installed url 126 | */ 127 | export const getWXAppInstallUrl = wrapApi(WeChat.getWXAppInstallUrl); 128 | 129 | /** 130 | * Get the wechat api version 131 | * @method getApiVersion 132 | * @return {String} the api version string 133 | */ 134 | export const getApiVersion = wrapApi(WeChat.getApiVersion); 135 | 136 | /** 137 | * Open wechat app 138 | * @method openWXApp 139 | * @return {Promise} 140 | */ 141 | export const openWXApp = wrapApi(WeChat.openWXApp); 142 | 143 | // wrap the APIs 144 | const nativeShareToTimeline = wrapApi(WeChat.shareToTimeline); 145 | const nativeLaunchMini = wrapApi(WeChat.launchMini); 146 | const nativeShareToSession = wrapApi(WeChat.shareToSession); 147 | const nativeSendAuthRequest = wrapApi(WeChat.sendAuthRequest); 148 | 149 | /** 150 | * @method sendAuthRequest 151 | * @param {Array} scopes - the scopes for authentication. 152 | * @return {Promise} 153 | */ 154 | export function sendAuthRequest(scopes, state) { 155 | return new Promise((resolve, reject) => { 156 | WeChat.sendAuthRequest(scopes, state, () => { 157 | }); 158 | emitter.once('SendAuth.Resp', resp => { 159 | if (resp.errCode === 0) { 160 | resolve(resp); 161 | } else { 162 | reject(new WechatError(resp)); 163 | } 164 | }); 165 | }); 166 | } 167 | 168 | /** 169 | * Share something to timeline/moments/朋友圈 170 | * @method shareToTimeline 171 | * @param {Object} data 172 | * @param {String} data.thumbImage - Thumb image of the message, which can be a uri or a resource id. 173 | * @param {String} data.type - Type of this message. Could be {news|text|imageUrl|imageFile|imageResource|video|audio|file|mini} 174 | * @param {String} data.webpageUrl - Required if type equals news or mini. The webpage link to share. 175 | * @param {String} data.userName - 小程序的原生id. 176 | * @param {String} data.path - 小程序页面的路径. 177 | * @param {String} data.hdImageData - 小程序节点高清大图,小于128k. 178 | * @param {Boolean} data.withShareTicket - 是否使用带 shareTicket 的转发 179 | * @param {Integer} data.miniProgramType - 分享小程序的版本(0-正式,1-开发,2-体验) 180 | * @param {String} data.webpageUrl - Required if type equals news. The webpage link to share. 181 | * @param {String} data.webpageUrl - Required if type equals news. The webpage link to share. 182 | * @param {String} data.imageUrl - Provide a remote image if type equals image. 183 | * @param {String} data.videoUrl - Provide a remote video if type equals video. 184 | * @param {String} data.musicUrl - Provide a remote music if type equals audio. 185 | * @param {String} data.filePath - Provide a local file if type equals file. 186 | * @param {String} data.fileExtension - Provide the file type if type equals file. 187 | */ 188 | export function shareToTimeline(data) { 189 | return new Promise((resolve, reject) => { 190 | nativeShareToTimeline(data); 191 | emitter.once('SendMessageToWX.Resp', resp => { 192 | if (resp.errCode === 0) { 193 | resolve(resp); 194 | } else { 195 | reject(new WechatError(resp)); 196 | } 197 | }); 198 | }); 199 | } 200 | 201 | /** 202 | * 打开小程序 203 | * @method launchMini 204 | * @param 205 | * @param {String} userName - 拉起的小程序的username 206 | * @param {Integer} miniProgramType - 拉起小程序的类型. 0-正式版 1-开发版 2-体验版 207 | * @param {String} path - 拉起小程序页面的可带参路径,不填默认拉起小程序首页 208 | */ 209 | export function launchMini({userName, miniProgramType = 0, path = ''}) { 210 | return new Promise((resolve, reject) => { 211 | if (miniProgramType !== 0 && miniProgramType !== 1 && miniProgramType !== 2) { 212 | reject(new WechatError({errStr: '拉起小程序的类型不对,0-正式版 1-开发版 2-体验版', errCode: -1})) 213 | return 214 | } 215 | nativeLaunchMini({userName, miniProgramType, path}); 216 | emitter.once('WXLaunchMiniProgramReq.Resp', resp => { 217 | if (resp.errCode === 0) { 218 | resolve(resp); 219 | } else { 220 | reject(new WechatError(resp)); 221 | } 222 | }); 223 | }); 224 | } 225 | 226 | /** 227 | * Share something to a friend or group 228 | * @method shareToSession 229 | * @param {Object} data 230 | * @param {String} data.thumbImage - Thumb image of the message, which can be a uri or a resource id. 231 | * @param {String} data.type - Type of this message. Could be {news|text|imageUrl|imageFile|imageResource|video|audio|file} 232 | * @param {String} data.webpageUrl - Required if type equals news. The webpage link to share. 233 | * @param {String} data.userName - 小程序的原生id. 234 | * @param {String} data.path - 小程序页面的路径. 235 | * @param {String} data.hdImageData - 小程序节点高清大图,小于128k. 236 | * @param {Boolean} data.withShareTicket - 是否使用带 shareTicket 的转发 237 | * @param {Integer} data.miniProgramType - 分享小程序的版本(0-正式,1-开发,2-体验) 238 | * @param {String} data.imageUrl - Provide a remote image if type equals image. 239 | * @param {String} data.videoUrl - Provide a remote video if type equals video. 240 | * @param {String} data.musicUrl - Provide a remote music if type equals audio. 241 | * @param {String} data.filePath - Provide a local file if type equals file. 242 | * @param {String} data.fileExtension - Provide the file type if type equals file. 243 | */ 244 | export function shareToSession(data) { 245 | return new Promise((resolve, reject) => { 246 | nativeShareToSession(data); 247 | emitter.once('SendMessageToWX.Resp', resp => { 248 | if (resp.errCode === 0) { 249 | resolve(resp); 250 | } else { 251 | reject(new WechatError(resp)); 252 | } 253 | }); 254 | }); 255 | } 256 | 257 | /** 258 | * wechat pay 259 | * @param {Object} data 260 | * @param {String} data.partnerId 261 | * @param {String} data.prepayId 262 | * @param {String} data.nonceStr 263 | * @param {String} data.timeStamp 264 | * @param {String} data.package 265 | * @param {String} data.sign 266 | * @returns {Promise} 267 | */ 268 | export function pay(data) { 269 | // FIXME(Yorkie): see https://github.com/yorkie/react-native-wechat/issues/203 270 | // Here the server-side returns params in lowercase, but here SDK requires timeStamp 271 | // for compatibility, we make this correction for users. 272 | function correct(actual, fixed) { 273 | if (!data[fixed] && data[actual]) { 274 | data[fixed] = data[actual]; 275 | delete data[actual]; 276 | } 277 | } 278 | 279 | correct('prepayid', 'prepayId'); 280 | correct('noncestr', 'nonceStr'); 281 | correct('partnerid', 'partnerId'); 282 | correct('timestamp', 'timeStamp'); 283 | 284 | return new Promise((resolve, reject) => { 285 | WeChat.pay(data, result => { 286 | if (result) reject(result); 287 | }); 288 | emitter.once('PayReq.Resp', resp => { 289 | if (resp.errCode === 0) { 290 | resolve(resp); 291 | } else { 292 | reject(new WechatError(resp)); 293 | } 294 | }); 295 | }); 296 | } 297 | 298 | /** 299 | * promises will reject with this error when API call finish with an errCode other than zero. 300 | */ 301 | export class WechatError extends Error { 302 | constructor(resp) { 303 | const message = resp.errStr || resp.errCode.toString(); 304 | super(message); 305 | this.name = 'WechatError'; 306 | this.code = resp.errCode; 307 | 308 | // avoid babel's limition about extending Error class 309 | // https://github.com/babel/babel/issues/3083 310 | if (typeof Object.setPrototypeOf === 'function') { 311 | Object.setPrototypeOf(this, WechatError.prototype); 312 | } else { 313 | this.__proto__ = WechatError.prototype; 314 | } 315 | } 316 | } 317 | 318 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # React-Native-Wechat 4 | 5 | [React Native] bridging library that integrates WeChat SDKs: 6 | 7 | - [x] iOS SDK 1.8.2 8 | - [x] Android SDK ++ 9 | 10 | [react-native-wechat] has the following tracking data in the open source world: 11 | 12 | | NPM | Dependency | Downloads | Build | 13 | | ------------------------------------ | ---------------------------------------------- | ---------------------------------------------- | ------------------------------------------- | 14 | | [![NPM version][npm-image]][npm-url] | [![Dependency Status][david-image]][david-url] | [![Downloads][downloads-image]][downloads-url] | [![Build Status][travis-image]][travis-url] | 15 | 16 | ## Table of Contents 17 | 18 | - [Getting Started](#getting-started) 19 | - [API Documentation](#api-documentation) 20 | - [Installation](#installation) 21 | - [Community](#community) 22 | - [Authors](#authors) 23 | - [License](#license) 24 | 25 | ## Getting Started 26 | 27 | - [Build setup on iOS](./docs/build-setup-ios.md) 28 | - [Build setup on Android](./docs/build-setup-android.md) 29 | 30 | ## API Documentation 31 | 32 | [react-native-wechat] uses Promises, therefore you can use `Promise` 33 | or `async/await` to manage your dataflow. 34 | 35 | #### registerApp(appid) 36 | 37 | - `appid` {String} the appid you get from WeChat dashboard 38 | - returns {Boolean} explains if your application is registered done 39 | 40 | This method should be called once globally. 41 | 42 | ```js 43 | import * as WeChat from 'react-native-wechat'; 44 | 45 | WeChat.registerApp('appid'); 46 | ``` 47 | 48 | #### registerAppWithDescription(appid, description) 49 | 50 | - `appid` {String} the appid you get from WeChat dashboard 51 | - `description` {String} the description of your app 52 | - returns {Boolean} explains if your application is registered done 53 | 54 | This method is only available on iOS. 55 | 56 | #### isWXAppInstalled() 57 | 58 | - returns {Boolean} if WeChat is installed. 59 | 60 | Check if the WeChat app is installed on the device. 61 | 62 | #### isWXAppSupportApi() (iOS平台) 63 | 64 | - returns {Boolean} Contains the result. 65 | 66 | Check if wechat support open url. 67 | #### isWXAppSupportApi(supportSdk) (Android平台) 68 | ```java 69 | //传入对应的字符串判断是否支持,没有找到微信文档,字面意思自己理解 70 | public static final int SDK_INT = 620824064; 71 | public static final int MIN_SDK_INT = 553713665; 72 | public static final int CHECK_TOKEN_SDK_INT = 620824064; 73 | public static final int TIMELINE_SUPPORTED_SDK_INT = 553779201; 74 | public static final int EMOJI_SUPPORTED_SDK_INT = 553844737; 75 | public static final int MUSIC_DATA_URL_SUPPORTED_SDK_INT = 553910273; 76 | public static final int PAY_SUPPORTED_SDK_INT = 570425345; 77 | public static final int OPENID_SUPPORTED_SDK_INT = 570425345; 78 | public static final int FAVORITE_SUPPPORTED_SDK_INT = 570425345; 79 | public static final int MESSAGE_ACTION_SUPPPORTED_SDK_INT = 570490883; 80 | public static final int SCAN_QRCODE_AUTH_SUPPORTED_SDK_INT = 587268097; 81 | public static final int MINIPROGRAM_SUPPORTED_SDK_INT = 620756993; 82 | public static final int VIDEO_FILE_SUPPORTED_SDK_INT = 620756996; 83 | public static final int SUBSCRIBE_MESSAGE_SUPPORTED_SDK_INT = 620756998; 84 | public static final int LAUNCH_MINIPROGRAM_SUPPORTED_SDK_INT = 620757000; 85 | public static final int CHOOSE_INVOICE_TILE_SUPPORT_SDK_INT = 620822528; 86 | public static final int INVOICE_AUTH_INSERT_SDK_INT = 620823552; 87 | public static final int NON_TAX_PAY_SDK_INT = 620823552; 88 | public static final int PAY_INSURANCE_SDK_INT = 620823552; 89 | public static final int SUBSCRIBE_MINI_PROGRAM_MSG_SUPPORTED_SDK_INT = 620823808; 90 | public static final int OFFLINE_PAY_SDK_INT = 620823808; 91 | public static final int SEND_TO_SPECIFIED_CONTACT_SDK_INT = 620824064; 92 | public static final int OPEN_BUSINESS_WEBVIEW_SDK_INT = 620824064; 93 | ``` 94 | - returns {Boolean} Contain the result. 95 | 96 | Check if wechat support open url. 97 | 98 | #### getApiVersion() 99 | 100 | - returns {String} Contains the result. 101 | 102 | Get the WeChat SDK api version. 103 | 104 | #### openWXApp() 105 | 106 | - returns {Boolean} 107 | 108 | Open the WeChat app from your application. 109 | 110 | #### sendAuthRequest([scope[, state]]) 111 | 112 | - `scope` {Array|String} Scopes of auth request. 113 | - `state` {String} the state of OAuth2 114 | - returns {Object} 115 | 116 | Send authentication request, and it returns an object with the 117 | following fields: 118 | 119 | | field | type | description | 120 | | ------- | ------ | ----------------------------------- | 121 | | errCode | Number | Error Code | 122 | | errStr | String | Error message if any error occurred | 123 | | openId | String | | 124 | | code | String | Authorization code | 125 | | url | String | The URL string | 126 | | lang | String | The user language | 127 | | country | String | The user country | 128 | 129 | #### class `ShareMetadata` 130 | 131 | - `type` {Number} type of this message. Can be {news|text|imageUrl|imageFile|imageResource|video|audio|file} 132 | - `thumbImage` {String} Thumb image of the message, which can be a uri or a resource id. 133 | - `description` {String} The description about the sharing. 134 | - `webpageUrl` {String} Required if type equals `news`. The webpage link to share. 135 | - `imageUrl` {String} Provide a remote image if type equals `image`. 136 | - `videoUrl` {String} Provide a remote video if type equals `video`. 137 | - `musicUrl` {String} Provide a remote music if type equals `audio`. 138 | - `filePath` {String} Provide a local file if type equals `file`. 139 | - `fileExtension` {String} Provide the file type if type equals `file`. 140 | 141 | #### shareToTimeline(message) 142 | 143 | - `message` {ShareMetadata} This object saves the metadata for sharing 144 | - returns {Object} 145 | 146 | Share a `ShareMetadata` message to timeline(朋友圈) and returns: 147 | 148 | | name | type | description | 149 | | ------- | ------ | ----------------------------------- | 150 | | errCode | Number | 0 if authorization successed | 151 | | errStr | String | Error message if any error occurred | 152 | 153 | The following examples require the 'react-native-chat' and 'react-native-fs' packages. 154 | 155 | ```js 156 | import * as WeChat from 'react-native-wechat'; 157 | import fs from 'react-native-fs'; 158 | let resolveAssetSource = require('resolveAssetSource'); 159 | 160 | // Code example to share text message: 161 | try { 162 | let result = await WeChat.shareToTimeline({ 163 | type: 'text', 164 | description: 'hello, wechat' 165 | }); 166 | console.log('share text message to time line successful:', result); 167 | } catch (e) { 168 | if (e instanceof WeChat.WechatError) { 169 | console.error(e.stack); 170 | } else { 171 | throw e; 172 | } 173 | } 174 | 175 | // Code example to share image url: 176 | // Share raw http(s) image from web will always fail with unknown reason, please use image file or image resource instead 177 | try { 178 | let result = await WeChat.shareToTimeline({ 179 | type: 'imageUrl', 180 | title: 'web image', 181 | description: 'share web image to time line', 182 | mediaTagName: 'email signature', 183 | messageAction: undefined, 184 | messageExt: undefined, 185 | imageUrl: 'http://www.ncloud.hk/email-signature-262x100.png' 186 | }); 187 | console.log('share image url to time line successful:', result); 188 | } catch (e) { 189 | if (e instanceof WeChat.WechatError) { 190 | console.error(e.stack); 191 | } else { 192 | throw e; 193 | } 194 | } 195 | 196 | // Code example to share image file: 197 | try { 198 | let rootPath = fs.DocumentDirectoryPath; 199 | let savePath = rootPath + '/email-signature-262x100.png'; 200 | console.log(savePath); 201 | 202 | /* 203 | * savePath on iOS may be: 204 | * /var/mobile/Containers/Data/Application/B1308E13-35F1-41AB-A20D-3117BE8EE8FE/Documents/email-signature-262x100.png 205 | * 206 | * savePath on Android may be: 207 | * /data/data/com.wechatsample/files/email-signature-262x100.png 208 | **/ 209 | await fs.downloadFile('http://www.ncloud.hk/email-signature-262x100.png', savePath); 210 | let result = await WeChat.shareToTimeline({ 211 | type: 'imageFile', 212 | title: 'image file download from network', 213 | description: 'share image file to time line', 214 | mediaTagName: 'email signature', 215 | messageAction: undefined, 216 | messageExt: undefined, 217 | imageUrl: "file://" + savePath // require the prefix on both iOS and Android platform 218 | }); 219 | console.log('share image file to time line successful:', result); 220 | } catch (e) { 221 | if (e instanceof WeChat.WechatError) { 222 | console.error(e.stack); 223 | } else { 224 | throw e; 225 | } 226 | } 227 | 228 | // Code example to share image resource: 229 | try { 230 | let imageResource = require('./email-signature-262x100.png'); 231 | let result = await WeChat.shareToTimeline({ 232 | type: 'imageResource', 233 | title: 'resource image', 234 | description: 'share resource image to time line', 235 | mediaTagName: 'email signature', 236 | messageAction: undefined, 237 | messageExt: undefined, 238 | imageUrl: resolveAssetSource(imageResource).uri 239 | }); 240 | console.log('share resource image to time line successful', result); 241 | } 242 | catch (e) { 243 | if (e instanceof WeChat.WechatError) { 244 | console.error(e.stack); 245 | } else { 246 | throw e; 247 | } 248 | } 249 | 250 | // Code example to download an word file from web, then share it to WeChat session 251 | // only support to share to session but time line 252 | // iOS code use DocumentDirectoryPath 253 | try { 254 | let rootPath = fs.DocumentDirectoryPath; 255 | let fileName = 'signature_method.doc'; 256 | /* 257 | * savePath on iOS may be: 258 | * /var/mobile/Containers/Data/Application/B1308E13-35F1-41AB-A20D-3117BE8EE8FE/Documents/signature_method.doc 259 | **/ 260 | let savePath = rootPath + '/' + fileName; 261 | 262 | await fs.downloadFile('https://open.weixin.qq.com/zh_CN/htmledition/res/assets/signature_method.doc', savePath); 263 | let result = await WeChat.shareToSession({ 264 | type: 'file', 265 | title: fileName, // WeChat app treat title as file name 266 | description: 'share word file to chat session', 267 | mediaTagName: 'word file', 268 | messageAction: undefined, 269 | messageExt: undefined, 270 | filePath: savePath, 271 | fileExtension: '.doc' 272 | }); 273 | console.log('share word file to chat session successful', result); 274 | } catch (e) { 275 | if (e instanceof WeChat.WechatError) { 276 | console.error(e.stack); 277 | } else { 278 | throw e; 279 | } 280 | } 281 | 282 | //android code use ExternalDirectoryPath 283 | try { 284 | let rootPath = fs.ExternalDirectoryPath; 285 | let fileName = 'signature_method.doc'; 286 | /* 287 | * savePath on Android may be: 288 | * /storage/emulated/0/Android/data/com.wechatsample/files/signature_method.doc 289 | **/ 290 | let savePath = rootPath + '/' + fileName; 291 | await fs.downloadFile('https://open.weixin.qq.com/zh_CN/htmledition/res/assets/signature_method.doc', savePath); 292 | let result = await WeChat.shareToSession({ 293 | type: 'file', 294 | title: fileName, // WeChat app treat title as file name 295 | description: 'share word file to chat session', 296 | mediaTagName: 'word file', 297 | messageAction: undefined, 298 | messageExt: undefined, 299 | filePath: savePath, 300 | fileExtension: '.doc' 301 | }); 302 | console.log('share word file to chat session successful', result); 303 | } 304 | catch (e) { 305 | if (e instanceof WeChat.WechatError) { 306 | console.error(e.stack); 307 | } else { 308 | throw e; 309 | } 310 | } 311 | ``` 312 | 313 | #### shareToSession(message) 314 | 315 | - `message` {ShareMetadata} This object saves the metadata for sharing 316 | - returns {Object} 317 | 318 | Similar to `shareToTimeline` but sends the message to a friend or chat group. 319 | 320 | #### launchMini(params) 321 | 322 | - `params` {Object} 打开小程序的参数 323 | 324 | - `userName` {String} 拉起的小程序的username 325 | 326 | - `miniProgramType` {Integer} 拉起小程序的类型. 0-正式版 1-开发版 2-体验版 327 | 328 | - `path` {String} 拉起小程序页面的可带参路径,不填默认拉起小程序首页 329 | 330 | 331 | 332 | #### pay(payload) 333 | 334 | - `payload` {Object} the payment data 335 | - `partnerId` {String} 商家向财付通申请的商家ID 336 | - `prepayId` {String} 预支付订单ID 337 | - `nonceStr` {String} 随机串 338 | - `timeStamp` {String} 时间戳 339 | - `package` {String} 商家根据财付通文档填写的数据和签名 340 | - `sign` {String} 商家根据微信开放平台文档对数据做的签名 341 | - returns {Object} 342 | 343 | Sends request for proceeding payment, then returns an object: 344 | 345 | | name | type | description | 346 | | ------- | ------ | ----------------------------------- | 347 | | errCode | Number | 0 if authorization successed | 348 | | errStr | String | Error message if any error occurred | 349 | 350 | ## Installation 351 | 352 | ```sh 353 | $ npm install react-native-wechat --save 354 | ``` 355 | 356 | ## Community 357 | 358 | #### IRC 359 | 360 | 361 | 362 | #### Tutorials 363 | 364 | - [react-native-wechat微信组件的使用](http://www.jianshu.com/p/3f424cccb888) 365 | - [超详细React Native实现微信好友/朋友圈分享功能-Android/iOS双平台通用](http://www.jianshu.com/p/ce5439dd1f52) 366 | - [柳轩涤俗 - 微信登录](http://www.cnblogs.com/zhangdw/p/6194345.html) 367 | 368 | #### Who's using it 369 | 370 | 371 | 372 | 373 | ## Authors 374 | 375 | | GitHub | Role | Email | 376 | |---------------|------------|-----------------------| 377 | | [@yorkie] | Author | yorkiefixer@gmail.com | 378 | | [@xing-zheng] | Emeriti | | 379 | | [@tdzl2003] | Emeriti | tdzl2003@gmail.com | 380 | 381 | [@yorkie]: https://github.com/yorkie 382 | [@xing-zheng]: https://github.com/xing-zheng 383 | [@tdzl2003]: https://github.com/tdzl2003 384 | 385 | ## License 386 | 387 | MIT 388 | 389 | [react-native-wechat]: https://github.com/yorkie/react-native-wechat 390 | [npm-image]: https://img.shields.io/npm/v/react-native-wechat.svg?style=flat-square 391 | [npm-url]: https://npmjs.org/package/react-native-wechat 392 | [travis-image]: https://img.shields.io/travis/yorkie/react-native-wechat.svg?style=flat-square 393 | [travis-url]: https://travis-ci.org/yorkie/react-native-wechat 394 | [david-image]: http://img.shields.io/david/yorkie/react-native-wechat.svg?style=flat-square 395 | [david-url]: https://david-dm.org/yorkie/react-native-wechat 396 | [downloads-image]: http://img.shields.io/npm/dm/react-native-wechat.svg?style=flat-square 397 | [downloads-url]: https://npmjs.org/package/react-native-wechat 398 | [React Native]: https://github.com/facebook/react-native 399 | [react-native-cn]: https://github.com/reactnativecn 400 | [WeChat SDK]: https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=1417674108&token=&lang=zh_CN 401 | [Linking Libraries iOS Guidance]: https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html 402 | 403 | -------------------------------------------------------------------------------- /ios/RCTWeChat.m: -------------------------------------------------------------------------------- 1 | // 2 | // RCTWeChat.m 3 | // RCTWeChat 4 | // 5 | // Created by Yorkie Liu on 10/16/15. 6 | // Copyright © 2015 WeFlex. All rights reserved. 7 | // 8 | 9 | #import "RCTWeChat.h" 10 | #import "WXApiObject.h" 11 | #import 12 | #import 13 | #import 14 | #import 15 | 16 | // Define error messages 17 | #define NOT_REGISTERED (@"registerApp required.") 18 | #define INVOKE_FAILED (@"WeChat API invoke returns false.") 19 | 20 | @implementation RCTWeChat 21 | 22 | @synthesize bridge = _bridge; 23 | 24 | RCT_EXPORT_MODULE() 25 | 26 | - (instancetype)init 27 | { 28 | self = [super init]; 29 | if (self) { 30 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil]; 31 | } 32 | return self; 33 | } 34 | 35 | - (void)dealloc 36 | { 37 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 38 | } 39 | 40 | - (BOOL)handleOpenURL:(NSNotification *)aNotification 41 | { 42 | NSString * aURLString = [aNotification userInfo][@"url"]; 43 | NSURL * aURL = [NSURL URLWithString:aURLString]; 44 | 45 | if ([WXApi handleOpenURL:aURL delegate:self]) 46 | { 47 | return YES; 48 | } else { 49 | return NO; 50 | } 51 | } 52 | 53 | - (dispatch_queue_t)methodQueue 54 | { 55 | return dispatch_get_main_queue(); 56 | } 57 | 58 | + (BOOL)requiresMainQueueSetup { 59 | return YES; 60 | } 61 | 62 | RCT_EXPORT_METHOD(registerApp:(NSString *)appid 63 | :(RCTResponseSenderBlock)callback) 64 | { 65 | self.appId = appid; 66 | callback(@[[WXApi registerApp:appid] ? [NSNull null] : INVOKE_FAILED]); 67 | } 68 | 69 | RCT_EXPORT_METHOD(isWXAppInstalled:(RCTResponseSenderBlock)callback) 70 | { 71 | callback(@[[NSNull null], @([WXApi isWXAppInstalled])]); 72 | } 73 | 74 | RCT_EXPORT_METHOD(isWXAppSupportApi:(RCTResponseSenderBlock)callback) 75 | { 76 | callback(@[[NSNull null], @([WXApi isWXAppSupportApi])]); 77 | } 78 | 79 | RCT_EXPORT_METHOD(getWXAppInstallUrl:(RCTResponseSenderBlock)callback) 80 | { 81 | callback(@[[NSNull null], [WXApi getWXAppInstallUrl]]); 82 | } 83 | 84 | RCT_EXPORT_METHOD(getApiVersion:(RCTResponseSenderBlock)callback) 85 | { 86 | callback(@[[NSNull null], [WXApi getApiVersion]]); 87 | } 88 | 89 | RCT_EXPORT_METHOD(openWXApp:(RCTResponseSenderBlock)callback) 90 | { 91 | callback(@[([WXApi openWXApp] ? [NSNull null] : INVOKE_FAILED)]); 92 | } 93 | 94 | RCT_EXPORT_METHOD(sendRequest:(NSString *)openid 95 | :(RCTResponseSenderBlock)callback) 96 | { 97 | BaseReq* req = [[BaseReq alloc] init]; 98 | req.openID = openid; 99 | callback(@[[WXApi sendReq:req] ? [NSNull null] : INVOKE_FAILED]); 100 | } 101 | 102 | RCT_EXPORT_METHOD(sendAuthRequest:(NSString *)scope 103 | :(NSString *)state 104 | :(RCTResponseSenderBlock)callback) 105 | { 106 | SendAuthReq* req = [[SendAuthReq alloc] init]; 107 | req.scope = scope; 108 | req.state = state; 109 | BOOL success = [WXApi sendReq:req]; 110 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 111 | } 112 | 113 | RCT_EXPORT_METHOD(sendSuccessResponse:(RCTResponseSenderBlock)callback) 114 | { 115 | BaseResp* resp = [[BaseResp alloc] init]; 116 | resp.errCode = WXSuccess; 117 | callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]); 118 | } 119 | 120 | RCT_EXPORT_METHOD(sendErrorCommonResponse:(NSString *)message 121 | :(RCTResponseSenderBlock)callback) 122 | { 123 | BaseResp* resp = [[BaseResp alloc] init]; 124 | resp.errCode = WXErrCodeCommon; 125 | resp.errStr = message; 126 | callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]); 127 | } 128 | 129 | RCT_EXPORT_METHOD(sendErrorUserCancelResponse:(NSString *)message 130 | :(RCTResponseSenderBlock)callback) 131 | { 132 | BaseResp* resp = [[BaseResp alloc] init]; 133 | resp.errCode = WXErrCodeUserCancel; 134 | resp.errStr = message; 135 | callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]); 136 | } 137 | 138 | RCT_EXPORT_METHOD(shareToTimeline:(NSDictionary *)data 139 | :(RCTResponseSenderBlock)callback) 140 | { 141 | [self shareToWeixinWithData:data scene:WXSceneTimeline callback:callback]; 142 | } 143 | 144 | RCT_EXPORT_METHOD(shareToSession:(NSDictionary *)data 145 | :(RCTResponseSenderBlock)callback) 146 | { 147 | [self shareToWeixinWithData:data scene:WXSceneSession callback:callback]; 148 | } 149 | RCT_EXPORT_METHOD(launchMini:(NSDictionary *)data 150 | :(RCTResponseSenderBlock)callback) 151 | { 152 | WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; 153 | launchMiniProgramReq.userName = data[@"userName"]; //拉起的小程序的username 154 | launchMiniProgramReq.path = data[@"path"]; //拉起小程序页面的可带参路径,不填默认拉起小程序首页 155 | //拉起小程序的类型 156 | launchMiniProgramReq.miniProgramType = [data[@"miniProgramType"] integerValue]; 157 | BOOL success = [WXApi sendReq:launchMiniProgramReq]; 158 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 159 | } 160 | 161 | RCT_EXPORT_METHOD(pay:(NSDictionary *)data 162 | :(RCTResponseSenderBlock)callback) 163 | { 164 | PayReq* req = [PayReq new]; 165 | req.partnerId = data[@"partnerId"]; 166 | req.prepayId = data[@"prepayId"]; 167 | req.nonceStr = data[@"nonceStr"]; 168 | req.timeStamp = [data[@"timeStamp"] unsignedIntValue]; 169 | req.package = data[@"package"]; 170 | req.sign = data[@"sign"]; 171 | BOOL success = [WXApi sendReq:req]; 172 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 173 | } 174 | 175 | - (void)shareToWeixinWithData:(NSDictionary *)aData 176 | thumbImage:(UIImage *)aThumbImage 177 | scene:(int)aScene 178 | callBack:(RCTResponseSenderBlock)callback 179 | { 180 | NSString *type = aData[RCTWXShareType]; 181 | 182 | if ([type isEqualToString:RCTWXShareTypeText]) { 183 | NSString *text = aData[RCTWXShareDescription]; 184 | [self shareToWeixinWithTextMessage:aScene Text:text callBack:callback]; 185 | } else { 186 | NSString * title = aData[RCTWXShareTitle]; 187 | NSString * description = aData[RCTWXShareDescription]; 188 | NSString * mediaTagName = aData[@"mediaTagName"]; 189 | NSString * messageAction = aData[@"messageAction"]; 190 | NSString * messageExt = aData[@"messageExt"]; 191 | 192 | if (type.length <= 0 || [type isEqualToString:RCTWXShareTypeNews]) { 193 | NSString * webpageUrl = aData[RCTWXShareWebpageUrl]; 194 | if (webpageUrl.length <= 0) { 195 | callback(@[@"webpageUrl required"]); 196 | return; 197 | } 198 | 199 | WXWebpageObject* webpageObject = [WXWebpageObject object]; 200 | webpageObject.webpageUrl = webpageUrl; 201 | 202 | [self shareToWeixinWithMediaMessage:aScene 203 | Title:title 204 | Description:description 205 | Object:webpageObject 206 | MessageExt:messageExt 207 | MessageAction:messageAction 208 | ThumbImage:aThumbImage 209 | MediaTag:mediaTagName 210 | callBack:callback]; 211 | 212 | } else if ([type isEqualToString:RCTWXShareTypeAudio]) { 213 | WXMusicObject *musicObject = [WXMusicObject new]; 214 | musicObject.musicUrl = aData[@"musicUrl"]; 215 | musicObject.musicLowBandUrl = aData[@"musicLowBandUrl"]; 216 | musicObject.musicDataUrl = aData[@"musicDataUrl"]; 217 | musicObject.musicLowBandDataUrl = aData[@"musicLowBandDataUrl"]; 218 | 219 | [self shareToWeixinWithMediaMessage:aScene 220 | Title:title 221 | Description:description 222 | Object:musicObject 223 | MessageExt:messageExt 224 | MessageAction:messageAction 225 | ThumbImage:aThumbImage 226 | MediaTag:mediaTagName 227 | callBack:callback]; 228 | 229 | } else if ([type isEqualToString:RCTWXShareTypeVideo]) { 230 | WXVideoObject *videoObject = [WXVideoObject new]; 231 | videoObject.videoUrl = aData[@"videoUrl"]; 232 | videoObject.videoLowBandUrl = aData[@"videoLowBandUrl"]; 233 | 234 | [self shareToWeixinWithMediaMessage:aScene 235 | Title:title 236 | Description:description 237 | Object:videoObject 238 | MessageExt:messageExt 239 | MessageAction:messageAction 240 | ThumbImage:aThumbImage 241 | MediaTag:mediaTagName 242 | callBack:callback]; 243 | 244 | } else if ([type isEqualToString:RCTWXShareTypeImageUrl] || 245 | [type isEqualToString:RCTWXShareTypeImageFile] || 246 | [type isEqualToString:RCTWXShareTypeImageResource]) { 247 | NSURL *url = [NSURL URLWithString:aData[RCTWXShareImageUrl]]; 248 | NSURLRequest *imageRequest = [NSURLRequest requestWithURL:url]; 249 | [self.bridge.imageLoader loadImageWithURLRequest:imageRequest callback:^(NSError *error, UIImage *image) { 250 | if (image == nil){ 251 | callback(@[@"fail to load image resource"]); 252 | } else { 253 | WXImageObject *imageObject = [WXImageObject object]; 254 | imageObject.imageData = UIImagePNGRepresentation(image); 255 | 256 | [self shareToWeixinWithMediaMessage:aScene 257 | Title:title 258 | Description:description 259 | Object:imageObject 260 | MessageExt:messageExt 261 | MessageAction:messageAction 262 | ThumbImage:aThumbImage 263 | MediaTag:mediaTagName 264 | callBack:callback]; 265 | 266 | } 267 | }]; 268 | } else if ([type isEqualToString:RCTWXShareTypeFile]) { 269 | NSString * filePath = aData[@"filePath"]; 270 | NSString * fileExtension = aData[@"fileExtension"]; 271 | 272 | WXFileObject *fileObject = [WXFileObject object]; 273 | fileObject.fileData = [NSData dataWithContentsOfFile:filePath]; 274 | fileObject.fileExtension = fileExtension; 275 | 276 | [self shareToWeixinWithMediaMessage:aScene 277 | Title:title 278 | Description:description 279 | Object:fileObject 280 | MessageExt:messageExt 281 | MessageAction:messageAction 282 | ThumbImage:aThumbImage 283 | MediaTag:mediaTagName 284 | callBack:callback]; 285 | 286 | } else if ([type isEqualToString:RCTWXShareTypeMini]) { 287 | 288 | WXMiniProgramObject *miniObject = [WXMiniProgramObject object]; 289 | miniObject.webpageUrl = aData[@"webpageUrl"]; 290 | miniObject.userName = aData[@"userName"]; 291 | miniObject.path = aData[@"path"]; 292 | miniObject.withShareTicket = [aData[@"withShareTicket"] boolValue]; 293 | miniObject.miniProgramType = [aData[@"miniProgramType"] integerValue]; 294 | miniObject.hdImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:aData[@"hdImageData"]]] ; 295 | 296 | [self shareToWeixinWithMediaMessage:aScene 297 | Title:title 298 | Description:description 299 | Object:miniObject 300 | MessageExt:messageExt 301 | MessageAction:messageAction 302 | ThumbImage:aThumbImage 303 | MediaTag:mediaTagName 304 | callBack:callback]; 305 | 306 | } else { 307 | callback(@[@"message type unsupported"]); 308 | } 309 | } 310 | } 311 | 312 | 313 | - (void)shareToWeixinWithData:(NSDictionary *)aData scene:(int)aScene callback:(RCTResponseSenderBlock)aCallBack 314 | { 315 | NSString *imageUrl = aData[RCTWXShareTypeThumbImageUrl]; 316 | if (imageUrl.length && _bridge.imageLoader) { 317 | NSURL *url = [NSURL URLWithString:imageUrl]; 318 | NSURLRequest *imageRequest = [NSURLRequest requestWithURL:url]; 319 | [_bridge.imageLoader loadImageWithURLRequest:imageRequest size:CGSizeMake(100, 100) scale:1 clipped:FALSE resizeMode:RCTResizeModeStretch progressBlock:nil partialLoadBlock:nil 320 | completionBlock:^(NSError *error, UIImage *image) { 321 | [self shareToWeixinWithData:aData thumbImage:image scene:aScene callBack:aCallBack]; 322 | }]; 323 | } else { 324 | [self shareToWeixinWithData:aData thumbImage:nil scene:aScene callBack:aCallBack]; 325 | } 326 | 327 | } 328 | 329 | - (void)shareToWeixinWithTextMessage:(int)aScene 330 | Text:(NSString *)text 331 | callBack:(RCTResponseSenderBlock)callback 332 | { 333 | SendMessageToWXReq* req = [SendMessageToWXReq new]; 334 | req.bText = YES; 335 | req.scene = aScene; 336 | req.text = text; 337 | 338 | BOOL success = [WXApi sendReq:req]; 339 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 340 | } 341 | 342 | - (void)shareToWeixinWithMediaMessage:(int)aScene 343 | Title:(NSString *)title 344 | Description:(NSString *)description 345 | Object:(id)mediaObject 346 | MessageExt:(NSString *)messageExt 347 | MessageAction:(NSString *)action 348 | ThumbImage:(UIImage *)thumbImage 349 | MediaTag:(NSString *)tagName 350 | callBack:(RCTResponseSenderBlock)callback 351 | { 352 | WXMediaMessage *message = [WXMediaMessage message]; 353 | message.title = title; 354 | message.description = description; 355 | message.mediaObject = mediaObject; 356 | message.messageExt = messageExt; 357 | message.messageAction = action; 358 | message.mediaTagName = tagName; 359 | [message setThumbImage:thumbImage]; 360 | 361 | SendMessageToWXReq* req = [SendMessageToWXReq new]; 362 | req.bText = NO; 363 | req.scene = aScene; 364 | req.message = message; 365 | 366 | BOOL success = [WXApi sendReq:req]; 367 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 368 | } 369 | 370 | #pragma mark - wx callback 371 | 372 | -(void) onReq:(BaseReq*)req 373 | { 374 | // TODO(Yorkie) 375 | } 376 | 377 | -(void) onResp:(BaseResp*)resp 378 | { 379 | if([resp isKindOfClass:[SendMessageToWXResp class]]) 380 | { 381 | SendMessageToWXResp *r = (SendMessageToWXResp *)resp; 382 | 383 | NSMutableDictionary *body = @{@"errCode":@(r.errCode)}.mutableCopy; 384 | body[@"errStr"] = r.errStr; 385 | body[@"lang"] = r.lang; 386 | body[@"country"] =r.country; 387 | body[@"type"] = @"SendMessageToWX.Resp"; 388 | [self.bridge.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 389 | } else if ([resp isKindOfClass:[SendAuthResp class]]) { 390 | SendAuthResp *r = (SendAuthResp *)resp; 391 | NSMutableDictionary *body = @{@"errCode":@(r.errCode)}.mutableCopy; 392 | body[@"errStr"] = r.errStr; 393 | body[@"state"] = r.state; 394 | body[@"lang"] = r.lang; 395 | body[@"country"] =r.country; 396 | body[@"type"] = @"SendAuth.Resp"; 397 | 398 | if (resp.errCode == WXSuccess) 399 | { 400 | [body addEntriesFromDictionary:@{@"appid":self.appId, @"code" :r.code}]; 401 | [self.bridge.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 402 | } 403 | else { 404 | [self.bridge.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 405 | } 406 | } else if ([resp isKindOfClass:[PayResp class]]) { 407 | PayResp *r = (PayResp *)resp; 408 | NSMutableDictionary *body = @{@"errCode":@(r.errCode)}.mutableCopy; 409 | body[@"errStr"] = r.errStr; 410 | body[@"type"] = @(r.type); 411 | body[@"returnKey"] =r.returnKey; 412 | body[@"type"] = @"PayReq.Resp"; 413 | [self.bridge.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 414 | }else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) 415 | { 416 | WXLaunchMiniProgramResp *r = (WXLaunchMiniProgramResp *)resp; 417 | NSMutableDictionary *body = @{@"errCode":@(r.errCode)}.mutableCopy; 418 | body[@"errStr"] = r.errStr; 419 | body[@"extMsg"] = r.extMsg; 420 | body[@"type"] = @"WXLaunchMiniProgramReq.Resp"; 421 | [self.bridge.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 422 | } 423 | } 424 | 425 | @end 426 | -------------------------------------------------------------------------------- /ios/WXApiObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // MMApiObject.h 3 | // Api对象,包含所有接口和对象数据定义 4 | // 5 | // Created by Wechat on 12-2-28. 6 | // Copyright (c) 2012年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | /*! @brief 错误码 12 | * 13 | */ 14 | enum WXErrCode { 15 | WXSuccess = 0, /**< 成功 */ 16 | WXErrCodeCommon = -1, /**< 普通错误类型 */ 17 | WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ 18 | WXErrCodeSentFail = -3, /**< 发送失败 */ 19 | WXErrCodeAuthDeny = -4, /**< 授权失败 */ 20 | WXErrCodeUnsupport = -5, /**< 微信不支持 */ 21 | }; 22 | 23 | 24 | 25 | /*! @brief 请求发送场景 26 | * 27 | */ 28 | enum WXScene { 29 | WXSceneSession = 0, /**< 聊天界面 */ 30 | WXSceneTimeline = 1, /**< 朋友圈 */ 31 | WXSceneFavorite = 2, /**< 收藏 */ 32 | }; 33 | 34 | 35 | 36 | enum WXAPISupport { 37 | WXAPISupportSession = 0, 38 | }; 39 | 40 | 41 | 42 | /*! @brief 跳转profile类型 43 | * 44 | */ 45 | enum WXBizProfileType{ 46 | WXBizProfileType_Normal = 0, //**< 普通公众号 */ 47 | WXBizProfileType_Device = 1, //**< 硬件公众号 */ 48 | }; 49 | 50 | /*! @brief 分享小程序类型 51 | * 52 | */ 53 | typedef NS_ENUM(NSUInteger, WXMiniProgramType){ 54 | WXMiniProgramTypeRelease = 0, //**< 正式版 */ 55 | WXMiniProgramTypeTest = 1, //**< 开发版 */ 56 | WXMiniProgramTypePreview = 2, //**< 体验版 */ 57 | }; 58 | 59 | /*! @brief 跳转mp网页类型 60 | * 61 | */ 62 | enum WXMPWebviewType { 63 | WXMPWebviewType_Ad = 0, /**< 广告网页 **/ 64 | }; 65 | 66 | 67 | 68 | /*! @brief 应用支持接收微信的文件类型 69 | * 70 | */ 71 | typedef NS_ENUM(UInt64, enAppSupportContentFlag) 72 | { 73 | MMAPP_SUPPORT_NOCONTENT = 0x0, 74 | MMAPP_SUPPORT_TEXT = 0x1, 75 | MMAPP_SUPPORT_PICTURE = 0x2, 76 | MMAPP_SUPPORT_LOCATION = 0x4, 77 | MMAPP_SUPPORT_VIDEO = 0x8, 78 | MMAPP_SUPPORT_AUDIO = 0x10, 79 | MMAPP_SUPPORT_WEBPAGE = 0x20, 80 | 81 | // Suport File Type 82 | MMAPP_SUPPORT_DOC = 0x40, // doc 83 | MMAPP_SUPPORT_DOCX = 0x80, // docx 84 | MMAPP_SUPPORT_PPT = 0x100, // ppt 85 | MMAPP_SUPPORT_PPTX = 0x200, // pptx 86 | MMAPP_SUPPORT_XLS = 0x400, // xls 87 | MMAPP_SUPPORT_XLSX = 0x800, // xlsx 88 | MMAPP_SUPPORT_PDF = 0x1000, // pdf 89 | }; 90 | 91 | /*! @brief log的级别 92 | * 93 | */ 94 | typedef NS_ENUM(NSInteger,WXLogLevel){ 95 | WXLogLevelNormal = 0, // 打印日常的日志 96 | WXLogLevelDetail = 1, // 打印详细的日志 97 | }; 98 | 99 | 100 | /*! @brief 打印回调的block 101 | * 102 | */ 103 | typedef void(^WXLogBolock)(NSString * log); 104 | 105 | #pragma mark - BaseReq 106 | /*! @brief 该类为微信终端SDK所有请求类的基类 107 | * 108 | */ 109 | @interface BaseReq : NSObject 110 | 111 | /** 请求类型 */ 112 | @property (nonatomic, assign) int type; 113 | /** 由用户微信号和AppID组成的唯一标识,发送请求时第三方程序必须填写,用于校验微信用户是否换号登录*/ 114 | @property (nonatomic, retain) NSString* openID; 115 | 116 | @end 117 | 118 | 119 | 120 | #pragma mark - BaseResp 121 | /*! @brief 该类为微信终端SDK所有响应类的基类 122 | * 123 | */ 124 | @interface BaseResp : NSObject 125 | /** 错误码 */ 126 | @property (nonatomic, assign) int errCode; 127 | /** 错误提示字符串 */ 128 | @property (nonatomic, retain) NSString *errStr; 129 | /** 响应类型 */ 130 | @property (nonatomic, assign) int type; 131 | 132 | @end 133 | 134 | 135 | 136 | #pragma mark - WXMediaMessage 137 | @class WXMediaMessage; 138 | 139 | #ifndef BUILD_WITHOUT_PAY 140 | 141 | /*! @brief 第三方向微信终端发起支付的消息结构体 142 | * 143 | * 第三方向微信终端发起支付的消息结构体,微信终端处理后会向第三方返回处理结果 144 | * @see PayResp 145 | */ 146 | @interface PayReq : BaseReq 147 | 148 | /** 商家向财付通申请的商家id */ 149 | @property (nonatomic, retain) NSString *partnerId; 150 | /** 预支付订单 */ 151 | @property (nonatomic, retain) NSString *prepayId; 152 | /** 随机串,防重发 */ 153 | @property (nonatomic, retain) NSString *nonceStr; 154 | /** 时间戳,防重发 */ 155 | @property (nonatomic, assign) UInt32 timeStamp; 156 | /** 商家根据财付通文档填写的数据和签名 */ 157 | @property (nonatomic, retain) NSString *package; 158 | /** 商家根据微信开放平台文档对数据做的签名 */ 159 | @property (nonatomic, retain) NSString *sign; 160 | 161 | @end 162 | 163 | #endif 164 | 165 | 166 | #ifndef BUILD_WITHOUT_PAY 167 | 168 | #pragma mark - PayResp 169 | /*! @brief 微信终端返回给第三方的关于支付结果的结构体 170 | * 171 | * 微信终端返回给第三方的关于支付结果的结构体 172 | */ 173 | @interface PayResp : BaseResp 174 | 175 | /** 财付通返回给商家的信息 */ 176 | @property (nonatomic, retain) NSString *returnKey; 177 | 178 | @end 179 | 180 | #endif 181 | 182 | 183 | 184 | #pragma mark - SendAuthReq 185 | /*! @brief 第三方程序向微信终端请求认证的消息结构 186 | * 187 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, 188 | * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 189 | * @see SendAuthResp 190 | */ 191 | @interface SendAuthReq : BaseReq 192 | /** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 193 | * @see SendAuthResp 194 | * @note scope字符串长度不能超过1K 195 | */ 196 | @property (nonatomic, retain) NSString* scope; 197 | /** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 198 | * @note state字符串长度不能超过1K 199 | */ 200 | @property (nonatomic, retain) NSString* state; 201 | @end 202 | 203 | 204 | 205 | #pragma mark - SendAuthResp 206 | /*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 207 | * 208 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 209 | * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 210 | * @see onResp 211 | */ 212 | @interface SendAuthResp : BaseResp 213 | @property (nonatomic, retain) NSString* code; 214 | /** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 215 | * @note state字符串长度不能超过1K 216 | */ 217 | @property (nonatomic, retain) NSString* state; 218 | @property (nonatomic, retain) NSString* lang; 219 | @property (nonatomic, retain) NSString* country; 220 | @end 221 | 222 | 223 | 224 | #pragma mark - SendMessageToWXReq 225 | /*! @brief 第三方程序发送消息至微信终端程序的消息结构体 226 | * 227 | * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, 228 | * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 229 | * @see SendMessageToWXResp 230 | */ 231 | @interface SendMessageToWXReq : BaseReq 232 | /** 发送消息的文本内容 233 | * @note 文本长度必须大于0且小于10K 234 | */ 235 | @property (nonatomic, retain) NSString* text; 236 | /** 发送消息的多媒体内容 237 | * @see WXMediaMessage 238 | */ 239 | @property (nonatomic, retain) WXMediaMessage* message; 240 | /** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 241 | @property (nonatomic, assign) BOOL bText; 242 | /** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 243 | * @see WXScene 244 | */ 245 | @property (nonatomic, assign) int scene; 246 | 247 | @end 248 | 249 | 250 | 251 | #pragma mark - SendMessageToWXResp 252 | /*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 253 | * 254 | * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 255 | */ 256 | @interface SendMessageToWXResp : BaseResp 257 | @property(nonatomic, retain) NSString* lang; 258 | @property(nonatomic, retain) NSString* country; 259 | @end 260 | 261 | 262 | 263 | #pragma mark - GetMessageFromWXReq 264 | /*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 265 | * 266 | * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, 267 | * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 268 | */ 269 | @interface GetMessageFromWXReq : BaseReq 270 | @property (nonatomic, retain) NSString* lang; 271 | @property (nonatomic, retain) NSString* country; 272 | @end 273 | 274 | 275 | 276 | #pragma mark - GetMessageFromWXResp 277 | /*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 278 | * 279 | * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 280 | */ 281 | @interface GetMessageFromWXResp : BaseResp 282 | /** 向微信终端提供的文本内容 283 | @note 文本长度必须大于0且小于10K 284 | */ 285 | @property (nonatomic, retain) NSString* text; 286 | /** 向微信终端提供的多媒体内容。 287 | * @see WXMediaMessage 288 | */ 289 | @property (nonatomic, retain) WXMediaMessage* message; 290 | /** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 291 | @property (nonatomic, assign) BOOL bText; 292 | @end 293 | 294 | 295 | 296 | #pragma mark - ShowMessageFromWXReq 297 | /*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 298 | * 299 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 300 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 301 | */ 302 | @interface ShowMessageFromWXReq : BaseReq 303 | /** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 304 | * @see WXMediaMessage 305 | */ 306 | @property (nonatomic, retain) WXMediaMessage* message; 307 | @property (nonatomic, retain) NSString* lang; 308 | @property (nonatomic, retain) NSString* country; 309 | @end 310 | 311 | 312 | 313 | #pragma mark - ShowMessageFromWXResp 314 | /*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 315 | * 316 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 317 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 318 | */ 319 | @interface ShowMessageFromWXResp : BaseResp 320 | @end 321 | 322 | 323 | 324 | #pragma mark - LaunchFromWXReq 325 | /*! @brief 微信终端打开第三方程序携带的消息结构体 326 | * 327 | * 微信向第三方发送的结构体,第三方不需要返回 328 | */ 329 | @interface LaunchFromWXReq : BaseReq 330 | @property (nonatomic, retain) WXMediaMessage* message; 331 | @property (nonatomic, retain) NSString* lang; 332 | @property (nonatomic, retain) NSString* country; 333 | @end 334 | 335 | #pragma mark - OpenTempSessionReq 336 | /* ! @brief 第三方通知微信,打开临时会话 337 | * 338 | * 第三方通知微信,打开临时会话 339 | */ 340 | @interface OpenTempSessionReq : BaseReq 341 | /** 需要打开的用户名 342 | * @attention 长度不能超过512字节 343 | */ 344 | @property (nonatomic, retain) NSString* username; 345 | /** 开发者自定义参数,拉起临时会话后会发给开发者后台,可以用于识别场景 346 | * @attention 长度不能超过32位 347 | */ 348 | @property (nonatomic, retain) NSString* sessionFrom; 349 | @end 350 | 351 | #pragma mark - OpenTempSessionResp 352 | /*! @brief 微信终端向第三方程序返回的OpenTempSessionReq处理结果。 353 | * 354 | * 第三方程序向微信终端发送OpenTempSessionReq后,微信发送回来的处理结果,该结果用OpenTempSessionResp表示。 355 | */ 356 | @interface OpenTempSessionResp : BaseResp 357 | 358 | @end 359 | 360 | #pragma mark - OpenWebviewReq 361 | /* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 362 | * 363 | * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 364 | */ 365 | @interface OpenWebviewReq : BaseReq 366 | /** 需要打开的网页对应的Url 367 | * @attention 长度不能超过1024 368 | */ 369 | @property(nonatomic,retain)NSString* url; 370 | 371 | @end 372 | 373 | #pragma mark - OpenWebviewResp 374 | /*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 375 | * 376 | * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 377 | */ 378 | @interface OpenWebviewResp : BaseResp 379 | 380 | @end 381 | 382 | #pragma mark - OpenRankListReq 383 | /* ! @brief 第三方通知微信,打开硬件排行榜 384 | * 385 | * 第三方通知微信,打开硬件排行榜 386 | */ 387 | @interface OpenRankListReq : BaseReq 388 | 389 | @end 390 | 391 | #pragma mark - OpenRanklistResp 392 | /*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 393 | * 394 | * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 395 | */ 396 | @interface OpenRankListResp : BaseResp 397 | 398 | @end 399 | 400 | #pragma mark - JumpToBizProfileReq 401 | /* ! @brief 第三方通知微信,打开指定微信号profile页面 402 | * 403 | * 第三方通知微信,打开指定微信号profile页面 404 | */ 405 | @interface JumpToBizProfileReq : BaseReq 406 | /** 跳转到该公众号的profile 407 | * @attention 长度不能超过512字节 408 | */ 409 | @property (nonatomic, retain) NSString* username; 410 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 411 | * @attention 长度不能超过1024字节 412 | */ 413 | @property (nonatomic, retain) NSString* extMsg; 414 | /** 415 | * 跳转的公众号类型 416 | * @see WXBizProfileType 417 | */ 418 | @property (nonatomic, assign) int profileType; 419 | @end 420 | 421 | 422 | 423 | #pragma mark - JumpToBizWebviewReq 424 | /* ! @brief 第三方通知微信,打开指定usrname的profile网页版 425 | * 426 | */ 427 | @interface JumpToBizWebviewReq : BaseReq 428 | /** 跳转的网页类型,目前只支持广告页 429 | * @see WXMPWebviewType 430 | */ 431 | @property(nonatomic, assign) int webType; 432 | /** 跳转到该公众号的profile网页版 433 | * @attention 长度不能超过512字节 434 | */ 435 | @property(nonatomic, retain) NSString* tousrname; 436 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 437 | * @attention 长度不能超过1024字节 438 | */ 439 | @property(nonatomic, retain) NSString* extMsg; 440 | 441 | @end 442 | 443 | #pragma mark - WXCardItem 444 | 445 | @interface WXCardItem : NSObject 446 | /** 卡id 447 | * @attention 长度不能超过1024字节 448 | */ 449 | @property (nonatomic,retain) NSString* cardId; 450 | /** ext信息 451 | * @attention 长度不能超过2024字节 452 | */ 453 | @property (nonatomic,retain) NSString* extMsg; 454 | /** 455 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 456 | */ 457 | @property (nonatomic,assign) UInt32 cardState; 458 | /** 459 | * @attention req不需要填,chooseCard返回的。 460 | */ 461 | @property (nonatomic,retain) NSString* encryptCode; 462 | /** 463 | * @attention req不需要填,chooseCard返回的。 464 | */ 465 | @property (nonatomic,retain) NSString* appID; 466 | @end; 467 | 468 | #pragma mark - WXInvoiceItem 469 | 470 | @interface WXInvoiceItem : NSObject 471 | /** 卡id 472 | * @attention 长度不能超过1024字节 473 | */ 474 | @property (nonatomic,retain) NSString* cardId; 475 | /** ext信息 476 | * @attention 长度不能超过2024字节 477 | */ 478 | @property (nonatomic,retain) NSString* extMsg; 479 | /** 480 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 481 | */ 482 | @property (nonatomic,assign) UInt32 cardState; 483 | /** 484 | * @attention req不需要填,chooseCard返回的。 485 | */ 486 | @property (nonatomic,retain) NSString* encryptCode; 487 | /** 488 | * @attention req不需要填,chooseCard返回的。 489 | */ 490 | @property (nonatomic,retain) NSString* appID; 491 | 492 | @end 493 | 494 | #pragma mark - AddCardToWXCardPackageReq 495 | /* ! @brief 请求添加卡券至微信卡包 496 | * 497 | */ 498 | 499 | @interface AddCardToWXCardPackageReq : BaseReq 500 | /** 卡列表 501 | * @attention 个数不能超过40个 类型WXCardItem 502 | */ 503 | @property (nonatomic,retain) NSArray* cardAry; 504 | 505 | @end 506 | 507 | 508 | #pragma mark - AddCardToWXCardPackageResp 509 | /** ! @brief 微信返回第三方添加卡券结果 510 | * 511 | */ 512 | 513 | @interface AddCardToWXCardPackageResp : BaseResp 514 | /** 卡列表 515 | * @attention 个数不能超过40个 类型WXCardItem 516 | */ 517 | @property (nonatomic,retain) NSArray* cardAry; 518 | @end 519 | 520 | #pragma mark - WXChooseCardReq 521 | /* ! @brief 请求从微信选取卡券 522 | * 523 | */ 524 | 525 | @interface WXChooseCardReq : BaseReq 526 | @property(nonatomic, strong) NSString *appID; 527 | @property(nonatomic, assign) UInt32 shopID; 528 | @property(nonatomic, assign) UInt32 canMultiSelect; 529 | @property(nonatomic, strong) NSString *cardType; 530 | @property(nonatomic, strong) NSString *cardTpID; 531 | @property(nonatomic, strong) NSString *signType; 532 | @property(nonatomic, strong) NSString *cardSign; 533 | @property(nonatomic, assign) UInt32 timeStamp; 534 | @property(nonatomic, strong) NSString *nonceStr; 535 | @end 536 | 537 | 538 | #pragma mark - WXChooseCardResp 539 | /** ! @brief 微信返回第三方请求选择卡券结果 540 | * 541 | */ 542 | 543 | @interface WXChooseCardResp : BaseResp 544 | @property (nonatomic,retain) NSArray* cardAry; 545 | @end 546 | 547 | 548 | #pragma mark - WXChooseInvoiceReq 549 | /* ! @brief 请求从微信选取发票 550 | * 551 | */ 552 | @interface WXChooseInvoiceReq : BaseReq 553 | @property (nonatomic, strong) NSString *appID; 554 | @property (nonatomic, assign) UInt32 shopID; 555 | @property (nonatomic, strong) NSString *signType; 556 | @property (nonatomic, strong) NSString *cardSign; 557 | @property (nonatomic, assign) UInt32 timeStamp; 558 | @property (nonatomic, strong) NSString *nonceStr; 559 | @end 560 | 561 | #pragma mark - WXChooseInvoiceResp 562 | /** ! @brief 微信返回第三方请求选择发票结果 563 | * 564 | */ 565 | @interface WXChooseInvoiceResp : BaseResp 566 | @property (nonatomic, strong) NSArray* cardAry; 567 | @end 568 | 569 | #pragma mark - WXSubscriptionReq 570 | @interface WXSubscribeMsgReq : BaseReq 571 | @property (nonatomic, assign) UInt32 scene; 572 | @property (nonatomic, strong) NSString * templateId; 573 | @property (nonatomic, strong) NSString * reserved; 574 | @end 575 | 576 | #pragma mark - WXSubscriptionReq 577 | @interface WXSubscribeMsgResp : BaseResp 578 | 579 | @property (nonatomic, strong) NSString *templateId; 580 | @property (nonatomic, assign) UInt32 scene; 581 | @property (nonatomic, strong) NSString *action; 582 | @property (nonatomic, strong) NSString * reserved; 583 | @property (nonatomic, strong) NSString * openId; 584 | 585 | @end 586 | 587 | #pragma mark - WXinvoiceAuthInsertReq 588 | @interface WXInvoiceAuthInsertReq : BaseReq 589 | 590 | @property (nonatomic, strong) NSString *urlString; 591 | 592 | @end 593 | 594 | #pragma mark - WXinvoiceAuthInsertResp 595 | 596 | @interface WXInvoiceAuthInsertResp : BaseResp 597 | 598 | @property (nonatomic, strong) NSString * wxOrderId; 599 | 600 | @end 601 | 602 | #pragma mark - WXNontaxPayReq 603 | @interface WXNontaxPayReq:BaseReq 604 | 605 | @property (nonatomic, strong) NSString *urlString; 606 | 607 | @end 608 | 609 | #pragma mark - WXNontaxPayResp 610 | @interface WXNontaxPayResp : BaseResp 611 | 612 | @property (nonatomic, strong) NSString *wxOrderId; 613 | 614 | @end 615 | 616 | #pragma mark - WXPayInsuranceReq 617 | @interface WXPayInsuranceReq : BaseReq 618 | 619 | @property (nonatomic, strong) NSString *urlString; 620 | 621 | @end 622 | 623 | #pragma mark - WXPayInsuranceResp 624 | @interface WXPayInsuranceResp : BaseResp 625 | 626 | @property (nonatomic, strong) NSString *wxOrderId; 627 | 628 | @end 629 | 630 | #pragma mark - WXMediaMessage 631 | 632 | 633 | #pragma mark - WXMediaMessage 634 | 635 | /*! @brief 多媒体消息结构体 636 | * 637 | * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 638 | */ 639 | @interface WXMediaMessage : NSObject 640 | 641 | +(WXMediaMessage *) message; 642 | 643 | /** 标题 644 | * @note 长度不能超过512字节 645 | */ 646 | @property (nonatomic, retain) NSString *title; 647 | /** 描述内容 648 | * @note 长度不能超过1K 649 | */ 650 | @property (nonatomic, retain) NSString *description; 651 | /** 缩略图数据 652 | * @note 大小不能超过32K 653 | */ 654 | @property (nonatomic, retain) NSData *thumbData; 655 | /** 656 | * @note 长度不能超过64字节 657 | */ 658 | @property (nonatomic, retain) NSString *mediaTagName; 659 | /** 660 | * 661 | */ 662 | @property (nonatomic, retain) NSString *messageExt; 663 | @property (nonatomic, retain) NSString *messageAction; 664 | /** 665 | * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 666 | */ 667 | @property (nonatomic, retain) id mediaObject; 668 | 669 | /*! @brief 设置消息缩略图的方法 670 | * 671 | * @param image 缩略图 672 | * @note 大小不能超过32K 673 | */ 674 | - (void) setThumbImage:(UIImage *)image; 675 | 676 | @end 677 | 678 | 679 | 680 | #pragma mark - WXImageObject 681 | /*! @brief 多媒体消息中包含的图片数据对象 682 | * 683 | * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 684 | * @note imageData成员不能为空 685 | * @see WXMediaMessage 686 | */ 687 | @interface WXImageObject : NSObject 688 | /*! @brief 返回一个WXImageObject对象 689 | * 690 | * @note 返回的WXImageObject对象是自动释放的 691 | */ 692 | +(WXImageObject *) object; 693 | 694 | /** 图片真实数据内容 695 | * @note 大小不能超过10M 696 | */ 697 | @property (nonatomic, retain) NSData *imageData; 698 | 699 | @end 700 | 701 | 702 | #pragma mark - WXMusicObject 703 | /*! @brief 多媒体消息中包含的音乐数据对象 704 | * 705 | * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 706 | * @note musicUrl和musicLowBandUrl成员不能同时为空。 707 | * @see WXMediaMessage 708 | */ 709 | @interface WXMusicObject : NSObject 710 | /*! @brief 返回一个WXMusicObject对象 711 | * 712 | * @note 返回的WXMusicObject对象是自动释放的 713 | */ 714 | +(WXMusicObject *) object; 715 | 716 | /** 音乐网页的url地址 717 | * @note 长度不能超过10K 718 | */ 719 | @property (nonatomic, retain) NSString *musicUrl; 720 | /** 音乐lowband网页的url地址 721 | * @note 长度不能超过10K 722 | */ 723 | @property (nonatomic, retain) NSString *musicLowBandUrl; 724 | /** 音乐数据url地址 725 | * @note 长度不能超过10K 726 | */ 727 | @property (nonatomic, retain) NSString *musicDataUrl; 728 | 729 | /**音乐lowband数据url地址 730 | * @note 长度不能超过10K 731 | */ 732 | @property (nonatomic, retain) NSString *musicLowBandDataUrl; 733 | 734 | @end 735 | 736 | 737 | 738 | #pragma mark - WXVideoObject 739 | /*! @brief 多媒体消息中包含的视频数据对象 740 | * 741 | * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 742 | * @note videoUrl和videoLowBandUrl不能同时为空。 743 | * @see WXMediaMessage 744 | */ 745 | @interface WXVideoObject : NSObject 746 | /*! @brief 返回一个WXVideoObject对象 747 | * 748 | * @note 返回的WXVideoObject对象是自动释放的 749 | */ 750 | +(WXVideoObject *) object; 751 | 752 | /** 视频网页的url地址 753 | * @note 长度不能超过10K 754 | */ 755 | @property (nonatomic, retain) NSString *videoUrl; 756 | /** 视频lowband网页的url地址 757 | * @note 长度不能超过10K 758 | */ 759 | @property (nonatomic, retain) NSString *videoLowBandUrl; 760 | 761 | @end 762 | 763 | 764 | 765 | #pragma mark - WXWebpageObject 766 | /*! @brief 多媒体消息中包含的网页数据对象 767 | * 768 | * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 769 | * @see WXMediaMessage 770 | */ 771 | @interface WXWebpageObject : NSObject 772 | /*! @brief 返回一个WXWebpageObject对象 773 | * 774 | * @note 返回的WXWebpageObject对象是自动释放的 775 | */ 776 | +(WXWebpageObject *) object; 777 | 778 | /** 网页的url地址 779 | * @note 不能为空且长度不能超过10K 780 | */ 781 | @property (nonatomic, retain) NSString *webpageUrl; 782 | 783 | @end 784 | 785 | 786 | 787 | #pragma mark - WXAppExtendObject 788 | /*! @brief 多媒体消息中包含的App扩展数据对象 789 | * 790 | * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, 791 | * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 792 | * @note url,extInfo和fileData不能同时为空 793 | * @see WXMediaMessage 794 | */ 795 | @interface WXAppExtendObject : NSObject 796 | /*! @brief 返回一个WXAppExtendObject对象 797 | * 798 | * @note 返回的WXAppExtendObject对象是自动释放的 799 | */ 800 | +(WXAppExtendObject *) object; 801 | 802 | /** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 803 | * @note 长度不能超过10K 804 | */ 805 | @property (nonatomic, retain) NSString *url; 806 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 807 | * @note 长度不能超过2K 808 | */ 809 | @property (nonatomic, retain) NSString *extInfo; 810 | /** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 811 | * @note 大小不能超过10M 812 | */ 813 | @property (nonatomic, retain) NSData *fileData; 814 | 815 | @end 816 | 817 | 818 | 819 | #pragma mark - WXEmoticonObject 820 | /*! @brief 多媒体消息中包含的表情数据对象 821 | * 822 | * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 823 | * @see WXMediaMessage 824 | */ 825 | @interface WXEmoticonObject : NSObject 826 | 827 | /*! @brief 返回一个WXEmoticonObject对象 828 | * 829 | * @note 返回的WXEmoticonObject对象是自动释放的 830 | */ 831 | +(WXEmoticonObject *) object; 832 | 833 | /** 表情真实数据内容 834 | * @note 大小不能超过10M 835 | */ 836 | @property (nonatomic, retain) NSData *emoticonData; 837 | 838 | @end 839 | 840 | 841 | 842 | #pragma mark - WXFileObject 843 | /*! @brief 多媒体消息中包含的文件数据对象 844 | * 845 | * @see WXMediaMessage 846 | */ 847 | @interface WXFileObject : NSObject 848 | 849 | /*! @brief 返回一个WXFileObject对象 850 | * 851 | * @note 返回的WXFileObject对象是自动释放的 852 | */ 853 | +(WXFileObject *) object; 854 | 855 | /** 文件后缀名 856 | * @note 长度不超过64字节 857 | */ 858 | @property (nonatomic, retain) NSString *fileExtension; 859 | 860 | /** 文件真实数据内容 861 | * @note 大小不能超过10M 862 | */ 863 | @property (nonatomic, retain) NSData *fileData; 864 | 865 | @end 866 | 867 | 868 | #pragma mark - WXLocationObject 869 | /*! @brief 多媒体消息中包含的地理位置数据对象 870 | * 871 | * 微信终端和第三方程序之间传递消息中包含的地理位置数据对象。 872 | * @see WXMediaMessage 873 | */ 874 | @interface WXLocationObject : NSObject 875 | 876 | /*! @brief 返回一个WXLocationObject对象 877 | * 878 | * @note 返回的WXLocationObject对象是自动释放的 879 | */ 880 | +(WXLocationObject *) object; 881 | 882 | /** 地理位置信息 883 | * @note 经纬度 884 | */ 885 | @property (nonatomic, assign) double lng; //经度 886 | @property (nonatomic, assign) double lat; //纬度 887 | 888 | @end 889 | 890 | @interface WXMiniProgramObject : NSObject 891 | 892 | /*! @brief WXMiniProgramObject对象 893 | * 894 | * @note 返回的WXMiniProgramObject对象是自动释放的 895 | */ 896 | +(WXMiniProgramObject *) object; 897 | 898 | @property (nonatomic, strong) NSString *webpageUrl; //低版本网页链接 899 | 900 | @property (nonatomic, strong) NSString *userName; //小程序username 901 | 902 | @property (nonatomic, strong) NSString *path; //小程序页面的路径 903 | 904 | @property (nonatomic, strong) NSData *hdImageData; // 小程序新版本的预览图 128k 905 | 906 | @property (nonatomic, assign) BOOL withShareTicket; //是否使用带 shareTicket 的转发 907 | 908 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; // 分享小程序的版本(正式,开发,体验) 909 | 910 | @end 911 | 912 | #pragma mark - WXLaunchMiniProgramReq 913 | 914 | /*! @brief WXLaunchMiniProgramReq对象, 可实现通过sdk拉起微信小程序 915 | * 916 | * @note 返回的WXLaunchMiniProgramReq对象是自动释放的 917 | */ 918 | @interface WXLaunchMiniProgramReq : BaseReq 919 | 920 | +(WXLaunchMiniProgramReq *) object; 921 | 922 | @property (nonatomic, strong) NSString *userName; //拉起的小程序的username 923 | @property (nonatomic, strong) NSString *path; //拉起小程序页面的路径,不填默认拉起小程序首页 924 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; //拉起小程序的类型 925 | 926 | @end 927 | 928 | #pragma mark - WXLaunchMiniProgramResp 929 | /*! @brief 微信终端向第三方程序返回的WXLaunchMiniProgramReq处理结果。 930 | * 931 | * 第三方程序向微信终端发送WXLaunchMiniProgramReq后,微信发送回来的处理结果,该结果用WXLaunchMiniProgramResp表示。 932 | */ 933 | @interface WXLaunchMiniProgramResp : BaseResp 934 | 935 | @property (nonatomic, retain) NSString *extMsg; 936 | 937 | @end 938 | 939 | 940 | #pragma mark - WXTextObject 941 | /*! @brief 多媒体消息中包含的文本数据对象 942 | * 943 | * 微信终端和第三方程序之间传递消息中包含的文本数据对象。 944 | * @see WXMediaMessage 945 | */ 946 | @interface WXTextObject : NSObject 947 | 948 | /*! @brief 返回一个WXTextObject对象 949 | * 950 | * @note 返回的WXTextObject对象是自动释放的 951 | */ 952 | +(WXTextObject *) object; 953 | 954 | /** 地理位置信息 955 | * @note 文本内容 956 | */ 957 | @property (nonatomic, retain) NSString *contentText; 958 | 959 | @end 960 | -------------------------------------------------------------------------------- /ios/RCTWeChat.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 10D6D7A71F160C250066F0F3 /* RCTWeChatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 10D6D7A61F160C250066F0F3 /* RCTWeChatTests.m */; }; 11 | 10D6D7A91F160C250066F0F3 /* libRCTWeChat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 86D238421BD0BB9E00C75D01 /* libRCTWeChat.a */; }; 12 | 10D6D7AF1F160C3A0066F0F3 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 10D6D76D1F160B090066F0F3 /* libReact.a */; }; 13 | 86D238561BD0BC1000C75D01 /* RCTWeChat.m in Sources */ = {isa = PBXBuildFile; fileRef = 86D238551BD0BC1000C75D01 /* RCTWeChat.m */; }; 14 | 86D2385D1BD0CA3D00C75D01 /* libWeChatSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 86D238571BD0BC2200C75D01 /* libWeChatSDK.a */; settings = {ATTRIBUTES = (Required, ); }; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXContainerItemProxy section */ 18 | 10D6D76C1F160B090066F0F3 /* PBXContainerItemProxy */ = { 19 | isa = PBXContainerItemProxy; 20 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 21 | proxyType = 2; 22 | remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192; 23 | remoteInfo = React; 24 | }; 25 | 10D6D76E1F160B090066F0F3 /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 28 | proxyType = 2; 29 | remoteGlobalIDString = 2D2A28131D9B038B00D4039D; 30 | remoteInfo = "React-tvOS"; 31 | }; 32 | 10D6D7701F160B090066F0F3 /* PBXContainerItemProxy */ = { 33 | isa = PBXContainerItemProxy; 34 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 35 | proxyType = 2; 36 | remoteGlobalIDString = 3D3C059A1DE3340900C268FA; 37 | remoteInfo = yoga; 38 | }; 39 | 10D6D7721F160B090066F0F3 /* PBXContainerItemProxy */ = { 40 | isa = PBXContainerItemProxy; 41 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 42 | proxyType = 2; 43 | remoteGlobalIDString = 3D3C06751DE3340C00C268FA; 44 | remoteInfo = "yoga-tvOS"; 45 | }; 46 | 10D6D7741F160B090066F0F3 /* PBXContainerItemProxy */ = { 47 | isa = PBXContainerItemProxy; 48 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 49 | proxyType = 2; 50 | remoteGlobalIDString = 3D3CD9251DE5FBEC00167DC4; 51 | remoteInfo = cxxreact; 52 | }; 53 | 10D6D7761F160B090066F0F3 /* PBXContainerItemProxy */ = { 54 | isa = PBXContainerItemProxy; 55 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 56 | proxyType = 2; 57 | remoteGlobalIDString = 3D3CD9321DE5FBEE00167DC4; 58 | remoteInfo = "cxxreact-tvOS"; 59 | }; 60 | 10D6D7781F160B090066F0F3 /* PBXContainerItemProxy */ = { 61 | isa = PBXContainerItemProxy; 62 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 63 | proxyType = 2; 64 | remoteGlobalIDString = 3D3CD90B1DE5FBD600167DC4; 65 | remoteInfo = jschelpers; 66 | }; 67 | 10D6D77A1F160B090066F0F3 /* PBXContainerItemProxy */ = { 68 | isa = PBXContainerItemProxy; 69 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 70 | proxyType = 2; 71 | remoteGlobalIDString = 3D3CD9181DE5FBD800167DC4; 72 | remoteInfo = "jschelpers-tvOS"; 73 | }; 74 | 10D6D77C1F160B090066F0F3 /* PBXContainerItemProxy */ = { 75 | isa = PBXContainerItemProxy; 76 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 77 | proxyType = 2; 78 | remoteGlobalIDString = 139D7ECE1E25DB7D00323FB7; 79 | remoteInfo = "third-party"; 80 | }; 81 | 10D6D77E1F160B090066F0F3 /* PBXContainerItemProxy */ = { 82 | isa = PBXContainerItemProxy; 83 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 84 | proxyType = 2; 85 | remoteGlobalIDString = 3D383D3C1EBD27B6005632C8; 86 | remoteInfo = "third-party-tvOS"; 87 | }; 88 | 10D6D7801F160B090066F0F3 /* PBXContainerItemProxy */ = { 89 | isa = PBXContainerItemProxy; 90 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 91 | proxyType = 2; 92 | remoteGlobalIDString = 139D7E881E25C6D100323FB7; 93 | remoteInfo = "double-conversion"; 94 | }; 95 | 10D6D7821F160B090066F0F3 /* PBXContainerItemProxy */ = { 96 | isa = PBXContainerItemProxy; 97 | containerPortal = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 98 | proxyType = 2; 99 | remoteGlobalIDString = 3D383D621EBD27B9005632C8; 100 | remoteInfo = "double-conversion-tvOS"; 101 | }; 102 | 10D6D7AA1F160C250066F0F3 /* PBXContainerItemProxy */ = { 103 | isa = PBXContainerItemProxy; 104 | containerPortal = 86D2383A1BD0BB9E00C75D01 /* Project object */; 105 | proxyType = 1; 106 | remoteGlobalIDString = 86D238411BD0BB9E00C75D01; 107 | remoteInfo = RCTWeChat; 108 | }; 109 | /* End PBXContainerItemProxy section */ 110 | 111 | /* Begin PBXCopyFilesBuildPhase section */ 112 | 86D238401BD0BB9E00C75D01 /* CopyFiles */ = { 113 | isa = PBXCopyFilesBuildPhase; 114 | buildActionMask = 2147483647; 115 | dstPath = "include/$(PRODUCT_NAME)"; 116 | dstSubfolderSpec = 16; 117 | files = ( 118 | ); 119 | runOnlyForDeploymentPostprocessing = 0; 120 | }; 121 | /* End PBXCopyFilesBuildPhase section */ 122 | 123 | /* Begin PBXFileReference section */ 124 | 10D6D75D1F160B090066F0F3 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; 125 | 10D6D7A41F160C250066F0F3 /* RCTWeChatTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RCTWeChatTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 126 | 10D6D7A61F160C250066F0F3 /* RCTWeChatTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTWeChatTests.m; sourceTree = ""; }; 127 | 10D6D7A81F160C250066F0F3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 128 | 86D238421BD0BB9E00C75D01 /* libRCTWeChat.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTWeChat.a; sourceTree = BUILT_PRODUCTS_DIR; }; 129 | 86D238541BD0BC1000C75D01 /* RCTWeChat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWeChat.h; sourceTree = SOURCE_ROOT; }; 130 | 86D238551BD0BC1000C75D01 /* RCTWeChat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTWeChat.m; sourceTree = SOURCE_ROOT; }; 131 | 86D238571BD0BC2200C75D01 /* libWeChatSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWeChatSDK.a; sourceTree = ""; }; 132 | 86D238581BD0BC2200C75D01 /* WXApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApi.h; sourceTree = ""; }; 133 | 86D238591BD0BC2200C75D01 /* WXApiObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApiObject.h; sourceTree = ""; }; 134 | /* End PBXFileReference section */ 135 | 136 | /* Begin PBXFrameworksBuildPhase section */ 137 | 10D6D7A11F160C250066F0F3 /* Frameworks */ = { 138 | isa = PBXFrameworksBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | 10D6D7AF1F160C3A0066F0F3 /* libReact.a in Frameworks */, 142 | 10D6D7A91F160C250066F0F3 /* libRCTWeChat.a in Frameworks */, 143 | ); 144 | runOnlyForDeploymentPostprocessing = 0; 145 | }; 146 | 86D2383F1BD0BB9E00C75D01 /* Frameworks */ = { 147 | isa = PBXFrameworksBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 86D2385D1BD0CA3D00C75D01 /* libWeChatSDK.a in Frameworks */, 151 | ); 152 | runOnlyForDeploymentPostprocessing = 0; 153 | }; 154 | /* End PBXFrameworksBuildPhase section */ 155 | 156 | /* Begin PBXGroup section */ 157 | 10D6D75E1F160B090066F0F3 /* Products */ = { 158 | isa = PBXGroup; 159 | children = ( 160 | 10D6D76D1F160B090066F0F3 /* libReact.a */, 161 | 10D6D76F1F160B090066F0F3 /* libReact.a */, 162 | 10D6D7711F160B090066F0F3 /* libyoga.a */, 163 | 10D6D7731F160B090066F0F3 /* libyoga.a */, 164 | 10D6D7751F160B090066F0F3 /* libcxxreact.a */, 165 | 10D6D7771F160B090066F0F3 /* libcxxreact.a */, 166 | 10D6D7791F160B090066F0F3 /* libjschelpers.a */, 167 | 10D6D77B1F160B090066F0F3 /* libjschelpers.a */, 168 | 10D6D77D1F160B090066F0F3 /* libthird-party.a */, 169 | 10D6D77F1F160B090066F0F3 /* libthird-party.a */, 170 | 10D6D7811F160B090066F0F3 /* libdouble-conversion.a */, 171 | 10D6D7831F160B090066F0F3 /* libdouble-conversion.a */, 172 | ); 173 | name = Products; 174 | sourceTree = ""; 175 | }; 176 | 10D6D7A51F160C250066F0F3 /* RCTWeChatTests */ = { 177 | isa = PBXGroup; 178 | children = ( 179 | 10D6D7A61F160C250066F0F3 /* RCTWeChatTests.m */, 180 | 10D6D7A81F160C250066F0F3 /* Info.plist */, 181 | ); 182 | path = RCTWeChatTests; 183 | sourceTree = ""; 184 | }; 185 | 86D238391BD0BB9E00C75D01 = { 186 | isa = PBXGroup; 187 | children = ( 188 | 86D238571BD0BC2200C75D01 /* libWeChatSDK.a */, 189 | 86D238581BD0BC2200C75D01 /* WXApi.h */, 190 | 86D238591BD0BC2200C75D01 /* WXApiObject.h */, 191 | 86D238441BD0BB9E00C75D01 /* RCTWeChat */, 192 | 10D6D7A51F160C250066F0F3 /* RCTWeChatTests */, 193 | 86D238431BD0BB9E00C75D01 /* Products */, 194 | 10D6D75D1F160B090066F0F3 /* React.xcodeproj */, 195 | ); 196 | sourceTree = ""; 197 | }; 198 | 86D238431BD0BB9E00C75D01 /* Products */ = { 199 | isa = PBXGroup; 200 | children = ( 201 | 86D238421BD0BB9E00C75D01 /* libRCTWeChat.a */, 202 | 10D6D7A41F160C250066F0F3 /* RCTWeChatTests.xctest */, 203 | ); 204 | name = Products; 205 | sourceTree = ""; 206 | }; 207 | 86D238441BD0BB9E00C75D01 /* RCTWeChat */ = { 208 | isa = PBXGroup; 209 | children = ( 210 | 86D238541BD0BC1000C75D01 /* RCTWeChat.h */, 211 | 86D238551BD0BC1000C75D01 /* RCTWeChat.m */, 212 | ); 213 | path = RCTWeChat; 214 | sourceTree = ""; 215 | }; 216 | /* End PBXGroup section */ 217 | 218 | /* Begin PBXNativeTarget section */ 219 | 10D6D7A31F160C250066F0F3 /* RCTWeChatTests */ = { 220 | isa = PBXNativeTarget; 221 | buildConfigurationList = 10D6D7AC1F160C250066F0F3 /* Build configuration list for PBXNativeTarget "RCTWeChatTests" */; 222 | buildPhases = ( 223 | 10D6D7A01F160C250066F0F3 /* Sources */, 224 | 10D6D7A11F160C250066F0F3 /* Frameworks */, 225 | 10D6D7A21F160C250066F0F3 /* Resources */, 226 | ); 227 | buildRules = ( 228 | ); 229 | dependencies = ( 230 | 10D6D7AB1F160C250066F0F3 /* PBXTargetDependency */, 231 | ); 232 | name = RCTWeChatTests; 233 | productName = RCTWeChatTests; 234 | productReference = 10D6D7A41F160C250066F0F3 /* RCTWeChatTests.xctest */; 235 | productType = "com.apple.product-type.bundle.unit-test"; 236 | }; 237 | 86D238411BD0BB9E00C75D01 /* RCTWeChat */ = { 238 | isa = PBXNativeTarget; 239 | buildConfigurationList = 86D2384B1BD0BB9E00C75D01 /* Build configuration list for PBXNativeTarget "RCTWeChat" */; 240 | buildPhases = ( 241 | 86D2383E1BD0BB9E00C75D01 /* Sources */, 242 | 86D2383F1BD0BB9E00C75D01 /* Frameworks */, 243 | 86D238401BD0BB9E00C75D01 /* CopyFiles */, 244 | ); 245 | buildRules = ( 246 | ); 247 | dependencies = ( 248 | ); 249 | name = RCTWeChat; 250 | productName = RCTWeChat; 251 | productReference = 86D238421BD0BB9E00C75D01 /* libRCTWeChat.a */; 252 | productType = "com.apple.product-type.library.static"; 253 | }; 254 | /* End PBXNativeTarget section */ 255 | 256 | /* Begin PBXProject section */ 257 | 86D2383A1BD0BB9E00C75D01 /* Project object */ = { 258 | isa = PBXProject; 259 | attributes = { 260 | LastUpgradeCheck = 0830; 261 | ORGANIZATIONNAME = WeFlex; 262 | TargetAttributes = { 263 | 10D6D7A31F160C250066F0F3 = { 264 | CreatedOnToolsVersion = 8.3.2; 265 | DevelopmentTeam = QMP96B5DPW; 266 | ProvisioningStyle = Automatic; 267 | }; 268 | 86D238411BD0BB9E00C75D01 = { 269 | CreatedOnToolsVersion = 7.0; 270 | DevelopmentTeam = JP4369ZCVM; 271 | }; 272 | }; 273 | }; 274 | buildConfigurationList = 86D2383D1BD0BB9E00C75D01 /* Build configuration list for PBXProject "RCTWeChat" */; 275 | compatibilityVersion = "Xcode 3.2"; 276 | developmentRegion = English; 277 | hasScannedForEncodings = 0; 278 | knownRegions = ( 279 | en, 280 | ); 281 | mainGroup = 86D238391BD0BB9E00C75D01; 282 | productRefGroup = 86D238431BD0BB9E00C75D01 /* Products */; 283 | projectDirPath = ""; 284 | projectReferences = ( 285 | { 286 | ProductGroup = 10D6D75E1F160B090066F0F3 /* Products */; 287 | ProjectRef = 10D6D75D1F160B090066F0F3 /* React.xcodeproj */; 288 | }, 289 | ); 290 | projectRoot = ""; 291 | targets = ( 292 | 86D238411BD0BB9E00C75D01 /* RCTWeChat */, 293 | 10D6D7A31F160C250066F0F3 /* RCTWeChatTests */, 294 | ); 295 | }; 296 | /* End PBXProject section */ 297 | 298 | /* Begin PBXReferenceProxy section */ 299 | 10D6D76D1F160B090066F0F3 /* libReact.a */ = { 300 | isa = PBXReferenceProxy; 301 | fileType = archive.ar; 302 | path = libReact.a; 303 | remoteRef = 10D6D76C1F160B090066F0F3 /* PBXContainerItemProxy */; 304 | sourceTree = BUILT_PRODUCTS_DIR; 305 | }; 306 | 10D6D76F1F160B090066F0F3 /* libReact.a */ = { 307 | isa = PBXReferenceProxy; 308 | fileType = archive.ar; 309 | path = libReact.a; 310 | remoteRef = 10D6D76E1F160B090066F0F3 /* PBXContainerItemProxy */; 311 | sourceTree = BUILT_PRODUCTS_DIR; 312 | }; 313 | 10D6D7711F160B090066F0F3 /* libyoga.a */ = { 314 | isa = PBXReferenceProxy; 315 | fileType = archive.ar; 316 | path = libyoga.a; 317 | remoteRef = 10D6D7701F160B090066F0F3 /* PBXContainerItemProxy */; 318 | sourceTree = BUILT_PRODUCTS_DIR; 319 | }; 320 | 10D6D7731F160B090066F0F3 /* libyoga.a */ = { 321 | isa = PBXReferenceProxy; 322 | fileType = archive.ar; 323 | path = libyoga.a; 324 | remoteRef = 10D6D7721F160B090066F0F3 /* PBXContainerItemProxy */; 325 | sourceTree = BUILT_PRODUCTS_DIR; 326 | }; 327 | 10D6D7751F160B090066F0F3 /* libcxxreact.a */ = { 328 | isa = PBXReferenceProxy; 329 | fileType = archive.ar; 330 | path = libcxxreact.a; 331 | remoteRef = 10D6D7741F160B090066F0F3 /* PBXContainerItemProxy */; 332 | sourceTree = BUILT_PRODUCTS_DIR; 333 | }; 334 | 10D6D7771F160B090066F0F3 /* libcxxreact.a */ = { 335 | isa = PBXReferenceProxy; 336 | fileType = archive.ar; 337 | path = libcxxreact.a; 338 | remoteRef = 10D6D7761F160B090066F0F3 /* PBXContainerItemProxy */; 339 | sourceTree = BUILT_PRODUCTS_DIR; 340 | }; 341 | 10D6D7791F160B090066F0F3 /* libjschelpers.a */ = { 342 | isa = PBXReferenceProxy; 343 | fileType = archive.ar; 344 | path = libjschelpers.a; 345 | remoteRef = 10D6D7781F160B090066F0F3 /* PBXContainerItemProxy */; 346 | sourceTree = BUILT_PRODUCTS_DIR; 347 | }; 348 | 10D6D77B1F160B090066F0F3 /* libjschelpers.a */ = { 349 | isa = PBXReferenceProxy; 350 | fileType = archive.ar; 351 | path = libjschelpers.a; 352 | remoteRef = 10D6D77A1F160B090066F0F3 /* PBXContainerItemProxy */; 353 | sourceTree = BUILT_PRODUCTS_DIR; 354 | }; 355 | 10D6D77D1F160B090066F0F3 /* libthird-party.a */ = { 356 | isa = PBXReferenceProxy; 357 | fileType = archive.ar; 358 | path = "libthird-party.a"; 359 | remoteRef = 10D6D77C1F160B090066F0F3 /* PBXContainerItemProxy */; 360 | sourceTree = BUILT_PRODUCTS_DIR; 361 | }; 362 | 10D6D77F1F160B090066F0F3 /* libthird-party.a */ = { 363 | isa = PBXReferenceProxy; 364 | fileType = archive.ar; 365 | path = "libthird-party.a"; 366 | remoteRef = 10D6D77E1F160B090066F0F3 /* PBXContainerItemProxy */; 367 | sourceTree = BUILT_PRODUCTS_DIR; 368 | }; 369 | 10D6D7811F160B090066F0F3 /* libdouble-conversion.a */ = { 370 | isa = PBXReferenceProxy; 371 | fileType = archive.ar; 372 | path = "libdouble-conversion.a"; 373 | remoteRef = 10D6D7801F160B090066F0F3 /* PBXContainerItemProxy */; 374 | sourceTree = BUILT_PRODUCTS_DIR; 375 | }; 376 | 10D6D7831F160B090066F0F3 /* libdouble-conversion.a */ = { 377 | isa = PBXReferenceProxy; 378 | fileType = archive.ar; 379 | path = "libdouble-conversion.a"; 380 | remoteRef = 10D6D7821F160B090066F0F3 /* PBXContainerItemProxy */; 381 | sourceTree = BUILT_PRODUCTS_DIR; 382 | }; 383 | /* End PBXReferenceProxy section */ 384 | 385 | /* Begin PBXResourcesBuildPhase section */ 386 | 10D6D7A21F160C250066F0F3 /* Resources */ = { 387 | isa = PBXResourcesBuildPhase; 388 | buildActionMask = 2147483647; 389 | files = ( 390 | ); 391 | runOnlyForDeploymentPostprocessing = 0; 392 | }; 393 | /* End PBXResourcesBuildPhase section */ 394 | 395 | /* Begin PBXSourcesBuildPhase section */ 396 | 10D6D7A01F160C250066F0F3 /* Sources */ = { 397 | isa = PBXSourcesBuildPhase; 398 | buildActionMask = 2147483647; 399 | files = ( 400 | 10D6D7A71F160C250066F0F3 /* RCTWeChatTests.m in Sources */, 401 | ); 402 | runOnlyForDeploymentPostprocessing = 0; 403 | }; 404 | 86D2383E1BD0BB9E00C75D01 /* Sources */ = { 405 | isa = PBXSourcesBuildPhase; 406 | buildActionMask = 2147483647; 407 | files = ( 408 | 86D238561BD0BC1000C75D01 /* RCTWeChat.m in Sources */, 409 | ); 410 | runOnlyForDeploymentPostprocessing = 0; 411 | }; 412 | /* End PBXSourcesBuildPhase section */ 413 | 414 | /* Begin PBXTargetDependency section */ 415 | 10D6D7AB1F160C250066F0F3 /* PBXTargetDependency */ = { 416 | isa = PBXTargetDependency; 417 | target = 86D238411BD0BB9E00C75D01 /* RCTWeChat */; 418 | targetProxy = 10D6D7AA1F160C250066F0F3 /* PBXContainerItemProxy */; 419 | }; 420 | /* End PBXTargetDependency section */ 421 | 422 | /* Begin XCBuildConfiguration section */ 423 | 10D6D7AD1F160C250066F0F3 /* Debug */ = { 424 | isa = XCBuildConfiguration; 425 | buildSettings = { 426 | CLANG_ANALYZER_NONNULL = YES; 427 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 428 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 429 | CLANG_WARN_INFINITE_RECURSION = YES; 430 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 431 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 432 | DEVELOPMENT_TEAM = QMP96B5DPW; 433 | INFOPLIST_FILE = RCTWeChatTests/Info.plist; 434 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 435 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 436 | PRODUCT_BUNDLE_IDENTIFIER = yorkie.RCTWeChatTests; 437 | PRODUCT_NAME = "$(TARGET_NAME)"; 438 | }; 439 | name = Debug; 440 | }; 441 | 10D6D7AE1F160C250066F0F3 /* Release */ = { 442 | isa = XCBuildConfiguration; 443 | buildSettings = { 444 | CLANG_ANALYZER_NONNULL = YES; 445 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 446 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 447 | CLANG_WARN_INFINITE_RECURSION = YES; 448 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 449 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 450 | DEVELOPMENT_TEAM = QMP96B5DPW; 451 | INFOPLIST_FILE = RCTWeChatTests/Info.plist; 452 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 453 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 454 | PRODUCT_BUNDLE_IDENTIFIER = yorkie.RCTWeChatTests; 455 | PRODUCT_NAME = "$(TARGET_NAME)"; 456 | }; 457 | name = Release; 458 | }; 459 | 86D238491BD0BB9E00C75D01 /* Debug */ = { 460 | isa = XCBuildConfiguration; 461 | buildSettings = { 462 | ALWAYS_SEARCH_USER_PATHS = NO; 463 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 464 | CLANG_CXX_LIBRARY = "libc++"; 465 | CLANG_ENABLE_MODULES = YES; 466 | CLANG_ENABLE_OBJC_ARC = YES; 467 | CLANG_WARN_BOOL_CONVERSION = YES; 468 | CLANG_WARN_CONSTANT_CONVERSION = YES; 469 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 470 | CLANG_WARN_EMPTY_BODY = YES; 471 | CLANG_WARN_ENUM_CONVERSION = YES; 472 | CLANG_WARN_INFINITE_RECURSION = YES; 473 | CLANG_WARN_INT_CONVERSION = YES; 474 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 475 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 476 | CLANG_WARN_UNREACHABLE_CODE = YES; 477 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 478 | COPY_PHASE_STRIP = NO; 479 | DEBUG_INFORMATION_FORMAT = dwarf; 480 | ENABLE_STRICT_OBJC_MSGSEND = YES; 481 | ENABLE_TESTABILITY = YES; 482 | GCC_C_LANGUAGE_STANDARD = gnu99; 483 | GCC_DYNAMIC_NO_PIC = NO; 484 | GCC_NO_COMMON_BLOCKS = YES; 485 | GCC_OPTIMIZATION_LEVEL = 0; 486 | GCC_PREPROCESSOR_DEFINITIONS = ( 487 | "DEBUG=1", 488 | "$(inherited)", 489 | ); 490 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 491 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 492 | GCC_WARN_UNDECLARED_SELECTOR = YES; 493 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 494 | GCC_WARN_UNUSED_FUNCTION = YES; 495 | GCC_WARN_UNUSED_VARIABLE = YES; 496 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 497 | MTL_ENABLE_DEBUG_INFO = YES; 498 | ONLY_ACTIVE_ARCH = YES; 499 | SDKROOT = iphoneos; 500 | }; 501 | name = Debug; 502 | }; 503 | 86D2384A1BD0BB9E00C75D01 /* Release */ = { 504 | isa = XCBuildConfiguration; 505 | buildSettings = { 506 | ALWAYS_SEARCH_USER_PATHS = NO; 507 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 508 | CLANG_CXX_LIBRARY = "libc++"; 509 | CLANG_ENABLE_MODULES = YES; 510 | CLANG_ENABLE_OBJC_ARC = YES; 511 | CLANG_WARN_BOOL_CONVERSION = YES; 512 | CLANG_WARN_CONSTANT_CONVERSION = YES; 513 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 514 | CLANG_WARN_EMPTY_BODY = YES; 515 | CLANG_WARN_ENUM_CONVERSION = YES; 516 | CLANG_WARN_INFINITE_RECURSION = YES; 517 | CLANG_WARN_INT_CONVERSION = YES; 518 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 519 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 520 | CLANG_WARN_UNREACHABLE_CODE = YES; 521 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 522 | COPY_PHASE_STRIP = NO; 523 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 524 | ENABLE_NS_ASSERTIONS = NO; 525 | ENABLE_STRICT_OBJC_MSGSEND = YES; 526 | GCC_C_LANGUAGE_STANDARD = gnu99; 527 | GCC_NO_COMMON_BLOCKS = YES; 528 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 529 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 530 | GCC_WARN_UNDECLARED_SELECTOR = YES; 531 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 532 | GCC_WARN_UNUSED_FUNCTION = YES; 533 | GCC_WARN_UNUSED_VARIABLE = YES; 534 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 535 | MTL_ENABLE_DEBUG_INFO = NO; 536 | SDKROOT = iphoneos; 537 | VALIDATE_PRODUCT = YES; 538 | }; 539 | name = Release; 540 | }; 541 | 86D2384C1BD0BB9E00C75D01 /* Debug */ = { 542 | isa = XCBuildConfiguration; 543 | buildSettings = { 544 | HEADER_SEARCH_PATHS = ( 545 | "$(inherited)", 546 | "$(SRCROOT)/../../React/**", 547 | "$(SRCROOT)/../react-native/React/**", 548 | "$(SRCROOT)/../node_modules/react-native/React/**", 549 | "$(SRCROOT)/../node_modules/react-native/Libraries/Image/**", 550 | ); 551 | LIBRARY_SEARCH_PATHS = ( 552 | "$(inherited)", 553 | "$(PROJECT_DIR)", 554 | ); 555 | OTHER_LDFLAGS = "-ObjC"; 556 | PRODUCT_NAME = "$(TARGET_NAME)"; 557 | SKIP_INSTALL = YES; 558 | }; 559 | name = Debug; 560 | }; 561 | 86D2384D1BD0BB9E00C75D01 /* Release */ = { 562 | isa = XCBuildConfiguration; 563 | buildSettings = { 564 | HEADER_SEARCH_PATHS = ( 565 | "$(inherited)", 566 | "$(SRCROOT)/../../React/**", 567 | "$(SRCROOT)/../react-native/React/**", 568 | "$(SRCROOT)/../node_modules/react-native/React/**", 569 | "$(SRCROOT)/../node_modules/react-native/Libraries/Image/**", 570 | ); 571 | LIBRARY_SEARCH_PATHS = ( 572 | "$(inherited)", 573 | "$(PROJECT_DIR)", 574 | ); 575 | OTHER_LDFLAGS = "-ObjC"; 576 | PRODUCT_NAME = "$(TARGET_NAME)"; 577 | SKIP_INSTALL = YES; 578 | }; 579 | name = Release; 580 | }; 581 | /* End XCBuildConfiguration section */ 582 | 583 | /* Begin XCConfigurationList section */ 584 | 10D6D7AC1F160C250066F0F3 /* Build configuration list for PBXNativeTarget "RCTWeChatTests" */ = { 585 | isa = XCConfigurationList; 586 | buildConfigurations = ( 587 | 10D6D7AD1F160C250066F0F3 /* Debug */, 588 | 10D6D7AE1F160C250066F0F3 /* Release */, 589 | ); 590 | defaultConfigurationIsVisible = 0; 591 | defaultConfigurationName = Release; 592 | }; 593 | 86D2383D1BD0BB9E00C75D01 /* Build configuration list for PBXProject "RCTWeChat" */ = { 594 | isa = XCConfigurationList; 595 | buildConfigurations = ( 596 | 86D238491BD0BB9E00C75D01 /* Debug */, 597 | 86D2384A1BD0BB9E00C75D01 /* Release */, 598 | ); 599 | defaultConfigurationIsVisible = 0; 600 | defaultConfigurationName = Release; 601 | }; 602 | 86D2384B1BD0BB9E00C75D01 /* Build configuration list for PBXNativeTarget "RCTWeChat" */ = { 603 | isa = XCConfigurationList; 604 | buildConfigurations = ( 605 | 86D2384C1BD0BB9E00C75D01 /* Debug */, 606 | 86D2384D1BD0BB9E00C75D01 /* Release */, 607 | ); 608 | defaultConfigurationIsVisible = 0; 609 | defaultConfigurationName = Release; 610 | }; 611 | /* End XCConfigurationList section */ 612 | }; 613 | rootObject = 86D2383A1BD0BB9E00C75D01 /* Project object */; 614 | } 615 | -------------------------------------------------------------------------------- /android/src/main/java/com/theweflex/react/WeChatModule.java: -------------------------------------------------------------------------------- 1 | package com.theweflex.react; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.net.Uri; 7 | import android.support.annotation.Nullable; 8 | 9 | import com.facebook.common.executors.UiThreadImmediateExecutorService; 10 | import com.facebook.common.references.CloseableReference; 11 | import com.facebook.common.util.UriUtil; 12 | import com.facebook.datasource.DataSource; 13 | import com.facebook.drawee.backends.pipeline.Fresco; 14 | import com.facebook.imagepipeline.common.ResizeOptions; 15 | import com.facebook.imagepipeline.core.ImagePipeline; 16 | import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber; 17 | import com.facebook.imagepipeline.image.CloseableImage; 18 | import com.facebook.imagepipeline.request.ImageRequest; 19 | import com.facebook.imagepipeline.request.ImageRequestBuilder; 20 | import com.facebook.react.bridge.Arguments; 21 | import com.facebook.react.bridge.Callback; 22 | import com.facebook.react.bridge.ReactApplicationContext; 23 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 24 | import com.facebook.react.bridge.ReactMethod; 25 | import com.facebook.react.bridge.ReadableMap; 26 | import com.facebook.react.bridge.WritableMap; 27 | import com.facebook.react.modules.core.DeviceEventManagerModule; 28 | import com.tencent.mm.opensdk.constants.Build; 29 | import com.tencent.mm.opensdk.constants.ConstantsAPI; 30 | import com.tencent.mm.opensdk.modelbase.BaseReq; 31 | import com.tencent.mm.opensdk.modelbase.BaseResp; 32 | import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram; 33 | import com.tencent.mm.opensdk.modelmsg.SendAuth; 34 | import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; 35 | import com.tencent.mm.opensdk.modelmsg.WXFileObject; 36 | import com.tencent.mm.opensdk.modelmsg.WXImageObject; 37 | import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; 38 | import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject; 39 | import com.tencent.mm.opensdk.modelmsg.WXMusicObject; 40 | import com.tencent.mm.opensdk.modelmsg.WXTextObject; 41 | import com.tencent.mm.opensdk.modelmsg.WXVideoObject; 42 | import com.tencent.mm.opensdk.modelmsg.WXWebpageObject; 43 | import com.tencent.mm.opensdk.modelpay.PayReq; 44 | import com.tencent.mm.opensdk.modelpay.PayResp; 45 | import com.tencent.mm.opensdk.openapi.IWXAPI; 46 | import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; 47 | import com.tencent.mm.opensdk.openapi.WXAPIFactory; 48 | 49 | import java.util.ArrayList; 50 | import java.util.UUID; 51 | 52 | /** 53 | * Created by tdzl2_000 on 2015-10-10. 54 | */ 55 | public class WeChatModule extends ReactContextBaseJavaModule implements IWXAPIEventHandler { 56 | private String appId; 57 | 58 | private IWXAPI api = null; 59 | private final static String NOT_REGISTERED = "registerApp required."; 60 | private final static String INVOKE_FAILED = "WeChat API invoke returns false."; 61 | private final static String INVALID_ARGUMENT = "invalid argument."; 62 | 63 | public WeChatModule(ReactApplicationContext context) { 64 | super(context); 65 | } 66 | 67 | @Override 68 | public String getName() { 69 | return "RCTWeChat"; 70 | } 71 | 72 | /** 73 | * fix Native module WeChatModule tried to override WeChatModule for module name RCTWeChat. 74 | * If this was your intention, return true from WeChatModule#canOverrideExistingModule() bug 75 | * 76 | * @return 77 | */ 78 | public boolean canOverrideExistingModule(){ 79 | return true; 80 | } 81 | 82 | private static ArrayList modules = new ArrayList<>(); 83 | 84 | @Override 85 | public void initialize() { 86 | super.initialize(); 87 | modules.add(this); 88 | } 89 | 90 | @Override 91 | public void onCatalystInstanceDestroy() { 92 | super.onCatalystInstanceDestroy(); 93 | if (api != null) { 94 | api = null; 95 | } 96 | modules.remove(this); 97 | } 98 | 99 | public static void handleIntent(Intent intent) { 100 | for (WeChatModule mod : modules) { 101 | mod.api.handleIntent(intent, mod); 102 | } 103 | } 104 | 105 | @ReactMethod 106 | public void registerApp(String appid, Callback callback) { 107 | this.appId = appid; 108 | api = WXAPIFactory.createWXAPI(this.getReactApplicationContext().getBaseContext(), appid, true); 109 | callback.invoke(null, api.registerApp(appid)); 110 | } 111 | 112 | @ReactMethod 113 | public void isWXAppInstalled(Callback callback) { 114 | if (api == null) { 115 | callback.invoke(NOT_REGISTERED); 116 | return; 117 | } 118 | callback.invoke(null, api.isWXAppInstalled()); 119 | } 120 | 121 | @ReactMethod 122 | public void isWXAppSupportApi(String supportApi, Callback callback) { 123 | if (api == null) { 124 | callback.invoke(NOT_REGISTERED); 125 | return; 126 | } 127 | int supportSDKINT = Build.PAY_SUPPORTED_SDK_INT; 128 | switch (supportApi) { 129 | case "SDK_INT": 130 | supportSDKINT = Build.SDK_INT; 131 | break; 132 | case "MIN_SDK_INT": 133 | supportSDKINT = Build.MIN_SDK_INT; 134 | break; 135 | case "CHECK_TOKEN_SDK_INT": 136 | supportSDKINT = Build.CHECK_TOKEN_SDK_INT; 137 | break; 138 | case "TIMELINE_SUPPORTED_SDK_INT": 139 | supportSDKINT = Build.TIMELINE_SUPPORTED_SDK_INT; 140 | break; 141 | case "EMOJI_SUPPORTED_SDK_INT": 142 | supportSDKINT = Build.EMOJI_SUPPORTED_SDK_INT; 143 | break; 144 | case "MUSIC_DATA_URL_SUPPORTED_SDK_INT": 145 | supportSDKINT = Build.MUSIC_DATA_URL_SUPPORTED_SDK_INT; 146 | break; 147 | case "PAY_SUPPORTED_SDK_INT": 148 | supportSDKINT = Build.PAY_SUPPORTED_SDK_INT; 149 | break; 150 | case "OPENID_SUPPORTED_SDK_INT": 151 | supportSDKINT = Build.OPENID_SUPPORTED_SDK_INT; 152 | break; 153 | case "FAVORITE_SUPPPORTED_SDK_INT": 154 | supportSDKINT = Build.FAVORITE_SUPPPORTED_SDK_INT; 155 | break; 156 | case "MESSAGE_ACTION_SUPPPORTED_SDK_INT": 157 | supportSDKINT = Build.MESSAGE_ACTION_SUPPPORTED_SDK_INT; 158 | break; 159 | case "SCAN_QRCODE_AUTH_SUPPORTED_SDK_INT": 160 | supportSDKINT = Build.SCAN_QRCODE_AUTH_SUPPORTED_SDK_INT; 161 | break; 162 | case "MINIPROGRAM_SUPPORTED_SDK_INT": 163 | supportSDKINT = Build.MINIPROGRAM_SUPPORTED_SDK_INT; 164 | break; 165 | case "VIDEO_FILE_SUPPORTED_SDK_INT": 166 | supportSDKINT = Build.VIDEO_FILE_SUPPORTED_SDK_INT; 167 | break; 168 | case "SUBSCRIBE_MESSAGE_SUPPORTED_SDK_INT": 169 | supportSDKINT = Build.SUBSCRIBE_MESSAGE_SUPPORTED_SDK_INT; 170 | break; 171 | case "LAUNCH_MINIPROGRAM_SUPPORTED_SDK_INT": 172 | supportSDKINT = Build.LAUNCH_MINIPROGRAM_SUPPORTED_SDK_INT; 173 | break; 174 | case "CHOOSE_INVOICE_TILE_SUPPORT_SDK_INT": 175 | supportSDKINT = Build.CHOOSE_INVOICE_TILE_SUPPORT_SDK_INT; 176 | break; 177 | case "INVOICE_AUTH_INSERT_SDK_INT": 178 | supportSDKINT = Build.INVOICE_AUTH_INSERT_SDK_INT; 179 | break; 180 | case "NON_TAX_PAY_SDK_INT": 181 | supportSDKINT = Build.NON_TAX_PAY_SDK_INT; 182 | break; 183 | case "PAY_INSURANCE_SDK_INT": 184 | supportSDKINT = Build.PAY_INSURANCE_SDK_INT; 185 | break; 186 | case "SUBSCRIBE_MINI_PROGRAM_MSG_SUPPORTED_SDK_INT": 187 | supportSDKINT = Build.SUBSCRIBE_MINI_PROGRAM_MSG_SUPPORTED_SDK_INT; 188 | break; 189 | case "OFFLINE_PAY_SDK_INT": 190 | supportSDKINT = Build.OFFLINE_PAY_SDK_INT; 191 | break; 192 | case "SEND_TO_SPECIFIED_CONTACT_SDK_INT": 193 | supportSDKINT = Build.SEND_TO_SPECIFIED_CONTACT_SDK_INT; 194 | break; 195 | case "OPEN_BUSINESS_WEBVIEW_SDK_INT": 196 | supportSDKINT = Build.OPEN_BUSINESS_WEBVIEW_SDK_INT; 197 | break; 198 | } 199 | boolean isWXAppSupportAPI = api.getWXAppSupportAPI() >= supportSDKINT; 200 | callback.invoke(null, isWXAppSupportAPI); 201 | } 202 | 203 | @ReactMethod 204 | public void getApiVersion(Callback callback) { 205 | if (api == null) { 206 | callback.invoke(NOT_REGISTERED); 207 | return; 208 | } 209 | callback.invoke(null, api.getWXAppSupportAPI()); 210 | } 211 | 212 | @ReactMethod 213 | public void openWXApp(Callback callback) { 214 | if (api == null) { 215 | callback.invoke(NOT_REGISTERED); 216 | return; 217 | } 218 | callback.invoke(null, api.openWXApp()); 219 | } 220 | 221 | @ReactMethod 222 | public void sendAuthRequest(String scope, String state, Callback callback) { 223 | if (api == null) { 224 | callback.invoke(NOT_REGISTERED); 225 | return; 226 | } 227 | SendAuth.Req req = new SendAuth.Req(); 228 | req.scope = scope; 229 | req.state = state; 230 | callback.invoke(null, api.sendReq(req)); 231 | } 232 | 233 | @ReactMethod 234 | public void shareToTimeline(ReadableMap data, Callback callback) { 235 | if (api == null) { 236 | callback.invoke(NOT_REGISTERED); 237 | return; 238 | } 239 | _share(SendMessageToWX.Req.WXSceneTimeline, data, callback); 240 | } 241 | 242 | @ReactMethod 243 | public void launchMini(ReadableMap data, Callback callback) { 244 | if (api == null) { 245 | callback.invoke(NOT_REGISTERED); 246 | return; 247 | } 248 | WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req(); 249 | req.userName = data.getString("userName"); // 填小程序原始id 250 | req.path = data.getString("path"); //拉起小程序页面的可带参路径,不填默认拉起小程序首页 251 | req.miniprogramType = data.getInt("miniProgramType");// 可选打开 开发版,体验版和正式版 252 | // req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版,体验版和正式版 253 | boolean success = api.sendReq(req); 254 | if (!success) callback.invoke(INVALID_ARGUMENT); 255 | } 256 | 257 | @ReactMethod 258 | public void shareToSession(ReadableMap data, Callback callback) { 259 | if (api == null) { 260 | callback.invoke(NOT_REGISTERED); 261 | return; 262 | } 263 | _share(SendMessageToWX.Req.WXSceneSession, data, callback); 264 | } 265 | 266 | @ReactMethod 267 | public void pay(ReadableMap data, Callback callback) { 268 | PayReq payReq = new PayReq(); 269 | if (data.hasKey("partnerId")) { 270 | payReq.partnerId = data.getString("partnerId"); 271 | } 272 | if (data.hasKey("prepayId")) { 273 | payReq.prepayId = data.getString("prepayId"); 274 | } 275 | if (data.hasKey("nonceStr")) { 276 | payReq.nonceStr = data.getString("nonceStr"); 277 | } 278 | if (data.hasKey("timeStamp")) { 279 | payReq.timeStamp = data.getString("timeStamp"); 280 | } 281 | if (data.hasKey("sign")) { 282 | payReq.sign = data.getString("sign"); 283 | } 284 | if (data.hasKey("package")) { 285 | payReq.packageValue = data.getString("package"); 286 | } 287 | if (data.hasKey("extData")) { 288 | payReq.extData = data.getString("extData"); 289 | } 290 | payReq.appId = appId; 291 | callback.invoke(api.sendReq(payReq) ? null : INVOKE_FAILED); 292 | } 293 | 294 | private void _share(final int scene, final ReadableMap data, final Callback callback) { 295 | Uri uri = null; 296 | if (data.hasKey("thumbImage") || data.hasKey("hdImageData")) { 297 | String imageUrl = data.hasKey("hdImageData") ? data.getString("hdImageData") : data.getString("thumbImage"); 298 | 299 | try { 300 | uri = Uri.parse(imageUrl); 301 | // Verify scheme is set, so that relative uri (used by static resources) are not handled. 302 | if (uri.getScheme() == null) { 303 | uri = getResourceDrawableUri(getReactApplicationContext(), imageUrl); 304 | } 305 | } catch (Exception e) { 306 | // ignore malformed uri, then attempt to extract resource ID. 307 | } 308 | } 309 | 310 | if (uri != null) { 311 | this._getImage(uri, new ResizeOptions(100, 100), new ImageCallback() { 312 | @Override 313 | public void invoke(@Nullable Bitmap bitmap) { 314 | WeChatModule.this._share(scene, data, bitmap, callback); 315 | } 316 | }); 317 | } else { 318 | this._share(scene, data, null, callback); 319 | } 320 | } 321 | 322 | private void _getImage(Uri uri, ResizeOptions resizeOptions, final ImageCallback imageCallback) { 323 | BaseBitmapDataSubscriber dataSubscriber = new BaseBitmapDataSubscriber() { 324 | @Override 325 | protected void onNewResultImpl(Bitmap bitmap) { 326 | bitmap = bitmap.copy(bitmap.getConfig(), true); 327 | imageCallback.invoke(bitmap); 328 | } 329 | 330 | @Override 331 | protected void onFailureImpl(DataSource> dataSource) { 332 | imageCallback.invoke(null); 333 | } 334 | }; 335 | 336 | ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri); 337 | if (resizeOptions != null) { 338 | builder = builder.setResizeOptions(resizeOptions); 339 | } 340 | ImageRequest imageRequest = builder.build(); 341 | 342 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 343 | DataSource> dataSource = imagePipeline.fetchDecodedImage(imageRequest, null); 344 | dataSource.subscribe(dataSubscriber, UiThreadImmediateExecutorService.getInstance()); 345 | } 346 | 347 | private static Uri getResourceDrawableUri(Context context, String name) { 348 | if (name == null || name.isEmpty()) { 349 | return null; 350 | } 351 | name = name.toLowerCase().replace("-", "_"); 352 | int resId = context.getResources().getIdentifier( 353 | name, 354 | "drawable", 355 | context.getPackageName()); 356 | 357 | if (resId == 0) { 358 | return null; 359 | } else { 360 | return new Uri.Builder() 361 | .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) 362 | .path(String.valueOf(resId)) 363 | .build(); 364 | } 365 | } 366 | 367 | private void _share(final int scene, final ReadableMap data, final Bitmap thumbImage, final Callback callback) { 368 | if (!data.hasKey("type")) { 369 | callback.invoke(INVALID_ARGUMENT); 370 | return; 371 | } 372 | String type = data.getString("type"); 373 | 374 | WXMediaMessage.IMediaObject mediaObject = null; 375 | if (type.equals("news")) { 376 | mediaObject = _jsonToWebpageMedia(data); 377 | } else if (type.equals("text")) { 378 | mediaObject = _jsonToTextMedia(data); 379 | } else if (type.equals("imageUrl") || type.equals("imageResource")) { 380 | __jsonToImageUrlMedia(data, new MediaObjectCallback() { 381 | @Override 382 | public void invoke(@Nullable WXMediaMessage.IMediaObject mediaObject) { 383 | if (mediaObject == null) { 384 | callback.invoke(INVALID_ARGUMENT); 385 | } else { 386 | WeChatModule.this._share(scene, data, thumbImage, mediaObject, callback); 387 | } 388 | } 389 | }); 390 | return; 391 | } else if (type.equals("imageFile")) { 392 | __jsonToImageFileMedia(data, new MediaObjectCallback() { 393 | @Override 394 | public void invoke(@Nullable WXMediaMessage.IMediaObject mediaObject) { 395 | if (mediaObject == null) { 396 | callback.invoke(INVALID_ARGUMENT); 397 | } else { 398 | WeChatModule.this._share(scene, data, thumbImage, mediaObject, callback); 399 | } 400 | } 401 | }); 402 | return; 403 | } else if (type.equals("video")) { 404 | mediaObject = __jsonToVideoMedia(data); 405 | } else if (type.equals("audio")) { 406 | mediaObject = __jsonToMusicMedia(data); 407 | } else if (type.equals("file")) { 408 | mediaObject = __jsonToFileMedia(data); 409 | } else if (type.equals("mini")) { 410 | mediaObject = __jsonToMiniMedia(data); 411 | } 412 | 413 | if (mediaObject == null) { 414 | callback.invoke(INVALID_ARGUMENT); 415 | } else { 416 | _share(scene, data, thumbImage, mediaObject, callback); 417 | } 418 | } 419 | 420 | private void _share(int scene, ReadableMap data, Bitmap thumbImage, WXMediaMessage.IMediaObject mediaObject, Callback callback) { 421 | 422 | WXMediaMessage message = new WXMediaMessage(); 423 | message.mediaObject = mediaObject; 424 | 425 | if (thumbImage != null) { 426 | message.setThumbImage(thumbImage); 427 | } 428 | if (data.hasKey("title")) { 429 | message.title = data.getString("title"); 430 | } 431 | if (data.hasKey("description")) { 432 | message.description = data.getString("description"); 433 | } 434 | if (data.hasKey("mediaTagName")) { 435 | message.mediaTagName = data.getString("mediaTagName"); 436 | } 437 | if (data.hasKey("messageAction")) { 438 | message.messageAction = data.getString("messageAction"); 439 | } 440 | if (data.hasKey("messageExt")) { 441 | message.messageExt = data.getString("messageExt"); 442 | } 443 | 444 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 445 | req.message = message; 446 | req.scene = scene; 447 | req.transaction = UUID.randomUUID().toString(); 448 | callback.invoke(null, api.sendReq(req)); 449 | } 450 | 451 | private WXTextObject _jsonToTextMedia(ReadableMap data) { 452 | if (!data.hasKey("description")) { 453 | return null; 454 | } 455 | 456 | WXTextObject ret = new WXTextObject(); 457 | ret.text = data.getString("description"); 458 | return ret; 459 | } 460 | 461 | private WXWebpageObject _jsonToWebpageMedia(ReadableMap data) { 462 | if (!data.hasKey("webpageUrl")) { 463 | return null; 464 | } 465 | 466 | WXWebpageObject ret = new WXWebpageObject(); 467 | ret.webpageUrl = data.getString("webpageUrl"); 468 | if (data.hasKey("extInfo")) { 469 | ret.extInfo = data.getString("extInfo"); 470 | } 471 | return ret; 472 | } 473 | 474 | private void __jsonToImageMedia(String imageUrl, final MediaObjectCallback callback) { 475 | Uri imageUri; 476 | try { 477 | imageUri = Uri.parse(imageUrl); 478 | // Verify scheme is set, so that relative uri (used by static resources) are not handled. 479 | if (imageUri.getScheme() == null) { 480 | imageUri = getResourceDrawableUri(getReactApplicationContext(), imageUrl); 481 | } 482 | } catch (Exception e) { 483 | imageUri = null; 484 | } 485 | 486 | if (imageUri == null) { 487 | callback.invoke(null); 488 | return; 489 | } 490 | 491 | this._getImage(imageUri, null, new ImageCallback() { 492 | @Override 493 | public void invoke(@Nullable Bitmap bitmap) { 494 | callback.invoke(bitmap == null ? null : new WXImageObject(bitmap)); 495 | } 496 | }); 497 | } 498 | 499 | private void __jsonToImageUrlMedia(ReadableMap data, MediaObjectCallback callback) { 500 | if (!data.hasKey("imageUrl")) { 501 | callback.invoke(null); 502 | return; 503 | } 504 | String imageUrl = data.getString("imageUrl"); 505 | __jsonToImageMedia(imageUrl, callback); 506 | } 507 | 508 | private void __jsonToImageFileMedia(ReadableMap data, MediaObjectCallback callback) { 509 | if (!data.hasKey("imageUrl")) { 510 | callback.invoke(null); 511 | return; 512 | } 513 | 514 | String imageUrl = data.getString("imageUrl"); 515 | if (!imageUrl.toLowerCase().startsWith("file://")) { 516 | imageUrl = "file://" + imageUrl; 517 | } 518 | __jsonToImageMedia(imageUrl, callback); 519 | } 520 | 521 | private WXMusicObject __jsonToMusicMedia(ReadableMap data) { 522 | if (!data.hasKey("musicUrl")) { 523 | return null; 524 | } 525 | 526 | WXMusicObject ret = new WXMusicObject(); 527 | ret.musicUrl = data.getString("musicUrl"); 528 | return ret; 529 | } 530 | 531 | private WXVideoObject __jsonToVideoMedia(ReadableMap data) { 532 | if (!data.hasKey("videoUrl")) { 533 | return null; 534 | } 535 | 536 | WXVideoObject ret = new WXVideoObject(); 537 | ret.videoUrl = data.getString("videoUrl"); 538 | return ret; 539 | } 540 | 541 | private WXFileObject __jsonToFileMedia(ReadableMap data) { 542 | if (!data.hasKey("filePath")) { 543 | return null; 544 | } 545 | return new WXFileObject(data.getString("filePath")); 546 | } 547 | 548 | private WXMiniProgramObject __jsonToMiniMedia(ReadableMap data) { 549 | if (!data.hasKey("userName")) { 550 | return null; 551 | } 552 | WXMiniProgramObject miniProgramObject = new WXMiniProgramObject(); 553 | miniProgramObject.userName = data.getString("userName"); 554 | if (data.hasKey("miniProgramType")) 555 | miniProgramObject.miniprogramType = data.getInt("miniProgramType"); 556 | if (data.hasKey("webpageUrl")) miniProgramObject.webpageUrl = data.getString("webpageUrl"); 557 | if (data.hasKey("path")) miniProgramObject.path = data.getString("path"); 558 | if (data.hasKey("withShareTicket")) 559 | miniProgramObject.withShareTicket = data.getBoolean("withShareTicket"); 560 | return miniProgramObject; 561 | } 562 | 563 | // TODO: 实现sendRequest、sendSuccessResponse、sendErrorCommonResponse、sendErrorUserCancelResponse 564 | 565 | @Override 566 | public void onReq(BaseReq baseReq) { 567 | 568 | } 569 | 570 | @Override 571 | public void onResp(BaseResp baseResp) { 572 | WritableMap map = Arguments.createMap(); 573 | map.putInt("errCode", baseResp.errCode); 574 | map.putString("errStr", baseResp.errStr); 575 | map.putString("openId", baseResp.openId); 576 | map.putString("transaction", baseResp.transaction); 577 | 578 | if (baseResp instanceof SendAuth.Resp) { 579 | SendAuth.Resp resp = (SendAuth.Resp) (baseResp); 580 | 581 | map.putString("type", "SendAuth.Resp"); 582 | map.putString("code", resp.code); 583 | map.putString("state", resp.state); 584 | map.putString("url", resp.url); 585 | map.putString("lang", resp.lang); 586 | map.putString("country", resp.country); 587 | } else if (baseResp instanceof SendMessageToWX.Resp) { 588 | SendMessageToWX.Resp resp = (SendMessageToWX.Resp) (baseResp); 589 | map.putString("type", "SendMessageToWX.Resp"); 590 | } else if (baseResp instanceof PayResp) { 591 | PayResp resp = (PayResp) (baseResp); 592 | map.putString("type", "PayReq.Resp"); 593 | map.putString("returnKey", resp.returnKey); 594 | } else if (baseResp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) { 595 | WXLaunchMiniProgram.Resp resp = (WXLaunchMiniProgram.Resp) baseResp; 596 | String extraData = resp.extMsg; // 对应JsApi navigateBackApplication中的extraData字段数据 597 | map.putString("extraData", extraData); 598 | } 599 | 600 | this.getReactApplicationContext() 601 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 602 | .emit("WeChat_Resp", map); 603 | } 604 | 605 | private interface ImageCallback { 606 | void invoke(@Nullable Bitmap bitmap); 607 | } 608 | 609 | private interface MediaObjectCallback { 610 | void invoke(@Nullable WXMediaMessage.IMediaObject mediaObject); 611 | } 612 | 613 | } 614 | --------------------------------------------------------------------------------