├── ios ├── Assets │ └── .gitkeep ├── Classes │ ├── FlutterWechatPlugin.h │ └── FlutterWechatPlugin.m ├── .gitignore └── flutter_wechat.podspec ├── android ├── gradle.properties ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── github │ │ └── xu │ │ └── flutterwechat │ │ └── FlutterWechatPlugin.java ├── build.gradle ├── gradlew.bat └── gradlew ├── .gitattributes ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── flutter_wechat_android.iml ├── pubspec.yaml ├── lib └── flutter_wechat.dart ├── README.md └── flutter_wechat.iml /ios/Assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'flutter_wechat' 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.java linguist-language=dart 2 | *.m linguist-language=dart 3 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pj0579/flutter_wechat/HEAD/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .atom/ 3 | .dart_tool/ 4 | .idea 5 | .packages 6 | .pub/ 7 | build/ 8 | ios/.generated/ 9 | packages 10 | pubspec.lock 11 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /ios/Classes/FlutterWechatPlugin.h: -------------------------------------------------------------------------------- 1 | #import 2 | #include "WXApi.h" 3 | @interface FlutterWechatPlugin : NSObject 4 | 5 | @end 6 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 12 14:58:32 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.0.1] - 2018.4.17 2 | * Support wechatShare. 3 | ## [0.0.2] - 2018.4.18 4 | * change README.md 5 | ## [0.0.7] - 2018.4.18 6 | * 移除调试输出 7 | ## [0.0.9] - 2018.4.19 8 | * 增加微信登录 9 | ## [0.1.0] - 2018.4.19 10 | * android ios统一返回 11 | ## [0.1.2] - 2018.4.22 12 | * 支付 13 | ## [0.1.5] - 2018.7.2 14 | * 删除测试Event回调 -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vagrant/ 3 | .sconsign.dblite 4 | .svn/ 5 | 6 | .DS_Store 7 | *.swp 8 | profile 9 | 10 | DerivedData/ 11 | build/ 12 | 13 | *.pbxuser 14 | *.mode1v3 15 | *.mode2v3 16 | *.perspectivev3 17 | 18 | !default.pbxuser 19 | !default.mode1v3 20 | !default.mode2v3 21 | !default.perspectivev3 22 | 23 | xcuserdata 24 | 25 | *.moved-aside 26 | 27 | *.pyc 28 | *sync/ 29 | Icon? 30 | .tags* 31 | 32 | -------------------------------------------------------------------------------- /ios/flutter_wechat.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 3 | # 4 | Pod::Spec.new do |s| 5 | s.name = 'flutter_wechat' 6 | s.version = '0.0.1' 7 | s.summary = 'A new flutter plugin project.' 8 | s.description = <<-DESC 9 | A new flutter plugin project. 10 | DESC 11 | s.homepage = 'http://example.com' 12 | s.license = { :file => '../LICENSE' } 13 | s.author = { 'Your Company' => 'email@example.com' } 14 | s.source = { :path => '.' } 15 | s.source_files = 'Classes/**/*' 16 | s.public_header_files = 'Classes/**/*.h' 17 | s.dependency 'Flutter' 18 | s.dependency 'WechatOpenSDK' 19 | s.ios.deployment_target = '8.0' 20 | end 21 | 22 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | group 'com.github.xu.flutterwechat' 2 | version '1.0-SNAPSHOT' 3 | 4 | buildscript { 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.0.1' 12 | } 13 | } 14 | 15 | rootProject.allprojects { 16 | repositories { 17 | google() 18 | jcenter() 19 | } 20 | } 21 | 22 | apply plugin: 'com.android.library' 23 | 24 | android { 25 | compileSdkVersion 27 26 | 27 | defaultConfig { 28 | minSdkVersion 16 29 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 30 | } 31 | lintOptions { 32 | disable 'InvalidPackage' 33 | } 34 | } 35 | dependencies { 36 | compile 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+' 37 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /flutter_wechat_android.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_wechat 2 | description: A flutter plugin to use wechat 3 | version: 0.1.5 4 | author: pj0579<1095584555@qq.com> 5 | homepage: https://github.com/pj0579/flutter_wechat 6 | environment: 7 | sdk: ">=2.0.0-dev.28.0 <3.0.0" 8 | flutter: ">=0.1.4 <2.0.0" 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | # For information on the generic Dart part of this file, see the 14 | # following page: https://www.dartlang.org/tools/pub/pubspec 15 | 16 | # The following section is specific to Flutter. 17 | flutter: 18 | plugin: 19 | androidPackage: com.github.xu.flutterwechat 20 | pluginClass: FlutterWechatPlugin 21 | 22 | # To add assets to your plugin package, add an assets section, like this: 23 | # assets: 24 | # - images/a_dot_burr.jpeg 25 | # - images/a_dot_ham.jpeg 26 | # 27 | # For details regarding assets in packages, see 28 | # https://flutter.io/assets-and-images/#from-packages 29 | # 30 | # An image asset can refer to one or more resolution-specific "variants", see 31 | # https://flutter.io/assets-and-images/#resolution-aware. 32 | 33 | # To add custom fonts to your plugin package, add a fonts section here, 34 | # in this "flutter" section. Each entry in this list should have a 35 | # "family" key with the font family name, and a "fonts" key with a 36 | # list giving the asset and other descriptors for the font. For 37 | # example: 38 | # fonts: 39 | # - family: Schyler 40 | # fonts: 41 | # - asset: fonts/Schyler-Regular.ttf 42 | # - asset: fonts/Schyler-Italic.ttf 43 | # style: italic 44 | # - family: Trajan Pro 45 | # fonts: 46 | # - asset: fonts/TrajanPro.ttf 47 | # - asset: fonts/TrajanPro_Bold.ttf 48 | # weight: 700 49 | # 50 | # For details regarding fonts in packages, see 51 | # https://flutter.io/custom-fonts/#from-packages 52 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/flutter_wechat.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/services.dart'; 4 | 5 | class FlutterWechat { 6 | String code; 7 | static const MethodChannel _channel = const MethodChannel('flutter_wechat'); 8 | 9 | static Future registerWechat(String wxId) async { 10 | var res=await _channel.invokeMethod( 11 | 'registerWechat', {'wxId': wxId}); 12 | return res; 13 | } 14 | 15 | 16 | static Future shareWebPage( 17 | {String webpageUrl: "", String title: "title", String description: "description", int type: 0, String imgUrl: ""}) async { 18 | final Map params = { 19 | 'webpageUrl': webpageUrl, 20 | 'title': title, 21 | 'description': description, 22 | 'type': type, 23 | 'imgUrl': imgUrl 24 | }; 25 | var res= await _channel.invokeMethod( 26 | 'shareWebPage', 27 | params); 28 | return res; 29 | } 30 | 31 | static Future shareText({String text: "", int type: 0}) async { 32 | final Map params = { 33 | 'type': type, 34 | 'text': text, 35 | 36 | }; 37 | var res=await _channel.invokeMethod( 38 | 'shareText', 39 | params); 40 | return res; 41 | } 42 | 43 | static Future shareImage({String imgUrl: "", int type: 0}) async { 44 | final Map params = { 45 | 'type': type, 46 | 'imgUrl': imgUrl, 47 | 48 | }; 49 | var res=await _channel.invokeMethod( 50 | 'shareImage', 51 | params); 52 | return res; 53 | } 54 | 55 | static Future shareMusic( 56 | {String imgUrl: "", int type: 0, String musicUrl: "", String title: "", String description: "", String musicDataUrl: "", String musicLowBandDataUrl: "", String musicLowBandUrl: ""}) async { 57 | final Map params = { 58 | 'type': type, 59 | 'imgUrl': imgUrl, 60 | 'musicUrl': musicUrl, 61 | 'title': title, 62 | 'description': description, 63 | 'musicDataUrl': musicDataUrl, 64 | 'musicLowBandDataUrl': musicLowBandDataUrl, 65 | 'musicLowBandUrl': musicLowBandUrl, 66 | }; 67 | var res=await _channel.invokeMethod( 68 | 'shareMusic', 69 | params); 70 | return res; 71 | } 72 | 73 | static Future shareVideo( 74 | {String imgUrl: "", int type: 0, String videoUrl: "", String title: "", String description: "", String videoLowBandUrl: ""}) async { 75 | final Map params = { 76 | 'type': type, 77 | 'imgUrl': imgUrl, 78 | 'videoUrl': videoUrl, 79 | 'title': title, 80 | 'description': description, 81 | 'videoLowBandUrl': videoLowBandUrl 82 | }; 83 | var res=await _channel.invokeMethod( 84 | 'shareVideo', 85 | params); 86 | return res; 87 | } 88 | 89 | static Future login( 90 | {String scope: "snsapi_userinfo", String state: "login",}) async { 91 | final Map params = { 92 | 'scope': scope, 93 | 'state': state 94 | }; 95 | var res=await _channel.invokeMethod( 96 | 'login', 97 | params); 98 | return res; 99 | } 100 | 101 | 102 | static Future pay({ 103 | String partnerId: "", 104 | String prepayId: "", 105 | String nonceStr: "", 106 | String timeStamp: "", 107 | String sign: "", 108 | String package: "", 109 | String appId: "", 110 | }) async { 111 | var res= await _channel.invokeMethod( 112 | 'pay'); 113 | return res; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /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 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_wechat 2 | 3 | A flutter plugin to use wechat. 4 | 测试使用暂时不维护了 有需要的请使用 https://github.com/OpenFlutter/fluwx 5 | ## Features 6 | - [X] Add Login 7 | - [X] Add Pay 8 | - [ ] Support LocalImage 9 | - [ ] Support 分享小程序 10 | ## Install 11 | Add this to your package's pubspec.yaml file: 12 | ``` 13 | dependencies: 14 | flutter_wechat: "^0.1.5" 15 | ``` 16 | ## Getting Started 17 | 18 | * Android 19 | * For Android, you must do the following before you can use the plugin: 20 | Add the permissions to your `AndroidManifest.xml` 21 | ``` 22 | 23 | 24 | 25 | 26 | 27 | 28 | ``` 29 | 如果想要响应微信分享登录resp需要在mainActivity同级目录下创建wxapi文件夹 30 | 下面新建WXEntryACtivity集成Activity(需要在`AndroidManifest.xml`注册) 31 | ``` 32 | 33 | ``` 34 | 35 | ``` 36 | private IWXAPI api; 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | api = WXAPIFactory.createWXAPI(this, "wxb25d3dec3db1affc", false); 41 | onNewIntent(getIntent()); 42 | finish(); 43 | } 44 | 45 | @Override 46 | public void onReq(BaseReq baseReq) { 47 | 48 | } 49 | 50 | @Override 51 | public void onResp(BaseResp baseResp) { 52 | sendBroadcastToWechat(baseResp); 53 | } 54 | 55 | private void sendBroadcastToWechat(BaseResp baseResp) { 56 | Intent intent = new Intent(); 57 | intent.setAction("sendResp"); 58 | if (baseResp instanceof SendAuth.Resp) { 59 | SendAuth.Resp resp = (SendAuth.Resp) (baseResp); 60 | intent.putExtra("code", resp.errCode == 0 ? resp.code : "-1"); 61 | intent.putExtra("type", "SendAuthResp"); 62 | sendBroadcast(intent); 63 | } else { 64 | intent.setAction("sendResp"); 65 | intent.putExtra("code", baseResp.errCode + ""); 66 | intent.putExtra("type", "ShareResp"); 67 | sendBroadcast(intent); 68 | } 69 | } 70 | protected void onNewIntent(Intent intent) { 71 | api.handleIntent(intent, this); 72 | } 73 | ``` 74 | 如果想要响应微信支付resp需要在mainActivity同级目录下创建wxapi文件夹(需要在`AndroidManifest.xml`注册) 75 | 76 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 |      下面新建WXEntryACtivity集成Activity 89 | ``` 90 | public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler { 91 | 92 | 93 | private IWXAPI api; 94 | 95 | @Override 96 | protected void onCreate(Bundle savedInstanceState) { 97 | super.onCreate(savedInstanceState); 98 | api = WXAPIFactory.createWXAPI(this, "wxb25d3dec3db1affc", false); 99 | onNewIntent(getIntent()); 100 | finish(); 101 | } 102 | 103 | @Override 104 | public void onReq(BaseReq baseReq) { 105 | 106 | } 107 | 108 | @Override 109 | public void onResp(BaseResp baseResp) { 110 | sendBroadcastToWechat(baseResp); 111 | } 112 | 113 | private void sendBroadcastToWechat(BaseResp baseResp) { 114 | Intent intent = new Intent(); 115 | intent.setAction("sendResp"); 116 | intent.putExtra("code", baseResp.errCode + ""); 117 | intent.putExtra("type", "PayResp"); 118 | sendBroadcast(intent); 119 | } 120 | 121 | protected void onNewIntent(Intent intent) { 122 | api.handleIntent(intent, this); 123 | } 124 | 125 | 126 | } 127 | ``` 128 | * IOS 129 | * add a wechat key. 130 | 在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id 131 | 参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=1417694084&token=&lang=zh_CN 132 |

133 | * 重写项目的AppDelegate的handleOpenURL和openURL方法         134 | ``` 135 | // ios 8.x or older 136 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 137 | sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 138 | { 139 | NSString * urlStr = [url absoluteString]; 140 | [[NSNotificationCenter defaultCenter] 141 | postNotificationName:@"WeChat" object:nil userInfo:@{@"url":urlStr}]; 142 | return YES; 143 | } 144 | ``` 145 | ``` 146 | // ios 9.0+ 147 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 148 | options:(NSDictionary *)options 149 | { 150 | NSString * urlStr = [url absoluteString]; 151 | [[NSNotificationCenter defaultCenter] 152 | postNotificationName:@"WeChat" object:nil userInfo:@{@"url":urlStr}]; 153 | return YES; 154 | } 155 | ``` 156 | 157 | ## How to use 158 | ``` 159 | import 'package:flutter_wechat/flutter_wechat.dart'; 160 | ``` 161 | ``` 162 | 分享返回错误码 0为正确 -1 -2 -3- 4- 5 163 | 登录成功返回 access_code 登录错误返回 -1 164 | 支付成功返回 0为正确 -1 -2 165 | ``` 166 | ``` 167 | 注册 168 | await FlutterWechat.registerWechat("wxxxxxx").then((state){print(state)});// 微信注册需要在你需要的地方注册,最好是app首页 169 | 分享 170 | await FlutterWechat.shareText(text: "test", type:0,).then((state){print(state)});//文字分享 type 0 聊天页面 1 朋友圈 171 | await FlutterWechat.shareImage(imgUrl: "xxx", type:0,).then((state){print(state)}); 172 | await FlutterWechat.shareMusic(imgUrl: "xxx", musicUrl:"",title:"",description:"",musicDataUrl:"",musicLowBandDataUrl:"",musicLowBandUrl:"",type:0,).then((state){print(state)}); 173 | await FlutterWechat.shareVideo(imgUrl: "xxx", videoUrl:"",title:"",description:"",videoLowBandUrl:"",type:0,).then((state){print(state)}); 174 | await FlutterWechat.shareWebPage(imgUrl: "xxx", webpageUrl:"",title:"",description:"",type:0,).then((state){print(state)}); 175 | 登录 176 | await FlutterWechat.login(scope:"",state:"").then((state){print(state)}); 177 | 支付 178 | await FlutterWechat.pay(partnerId: "",prepayId: "",nonceStr: "",timeStamp: "",sign: "",package: "",appId: "",).then((state){print(state)});//具体参考微信参数传递 179 | ``` 180 | -------------------------------------------------------------------------------- /ios/Classes/FlutterWechatPlugin.m: -------------------------------------------------------------------------------- 1 | #import "FlutterWechatPlugin.h" 2 | 3 | @implementation FlutterWechatPlugin { 4 | FlutterResult res; 5 | } 6 | - (instancetype)init 7 | { 8 | self = [super init]; 9 | [[NSNotificationCenter defaultCenter] addObserver:self 10 | selector:@selector(handleOpenURL:) 11 | name:@"WeChat" 12 | object:nil]; 13 | return self; 14 | } 15 | - (void)dealloc 16 | { 17 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 18 | } 19 | + (void)registerWithRegistrar:(NSObject*)registrar { 20 | FlutterMethodChannel* channel = [FlutterMethodChannel 21 | methodChannelWithName:@"flutter_wechat" 22 | binaryMessenger:[registrar messenger]]; 23 | FlutterWechatPlugin* instance = [[FlutterWechatPlugin alloc] init]; 24 | [registrar addMethodCallDelegate:instance channel:channel]; 25 | } 26 | 27 | - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { 28 | res=result; 29 | NSDictionary *arguments = [call arguments]; 30 | NSNumber* wxType = arguments[@"type"]; 31 | int type=[wxType intValue]; 32 | if ([@"registerWechat" isEqualToString:call.method]) { 33 | [WXApi registerApp:arguments[@"wxId"]]; 34 | res(nil); 35 | } 36 | else if([@"shareText" isEqualToString:call.method]) { 37 | NSString* text= arguments[@"text"]; 38 | SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init]; 39 | req.text = text; 40 | req.bText = YES; 41 | req.scene = type==0?WXSceneSession:WXSceneTimeline; 42 | [WXApi sendReq:req]; 43 | }else if([@"shareImage" isEqualToString:call.method]){ 44 | NSString* imgUrl= arguments[@"imgUrl"]; 45 | WXMediaMessage *mediaMsg = [WXMediaMessage message]; 46 | WXImageObject *imgObj = [WXImageObject object]; 47 | imgObj.imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]]; 48 | mediaMsg.mediaObject = imgObj; 49 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 50 | req.message = mediaMsg; 51 | req.bText = NO; 52 | req.scene = type==0?WXSceneSession:WXSceneTimeline; 53 | [WXApi sendReq:req]; 54 | }else if([@"shareWebPage" isEqualToString:call.method]){ 55 | NSString* webpageUrl= arguments[@"webpageUrl"]; 56 | NSString* imgUrl= arguments[@"imgUrl"]; 57 | NSString* webTitle= arguments[@"title"]; 58 | NSString* webDescription= arguments[@"description"]; 59 | WXMediaMessage* message =[WXMediaMessage message]; 60 | message.title = webTitle; 61 | message.description =webDescription; 62 | NSData* data=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]]; 63 | [message setThumbImage:[UIImage imageWithData:data]]; 64 | WXWebpageObject* webpageObject = [WXWebpageObject object]; 65 | webpageObject.webpageUrl =webpageUrl; 66 | message.mediaObject = webpageObject; 67 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 68 | req.message = message; 69 | req.bText = NO; 70 | req.scene = type==0?WXSceneSession:WXSceneTimeline; 71 | [WXApi sendReq:req]; 72 | }else if([@"shareMusic" isEqualToString:call.method]){ 73 | NSString* musicUrl= arguments[@"musicUrl"]; 74 | NSString* imgUrl= arguments[@"imgUrl"]; 75 | NSString* musicTitle= arguments[@"title"]; 76 | NSString* musicDescription= arguments[@"description"]; 77 | NSString* musicDataUrl= arguments[@"musicDataUrl"]; 78 | WXMediaMessage* message =[WXMediaMessage message]; 79 | message.title = musicTitle; 80 | message.description =musicDescription; 81 | NSData* data=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]]; 82 | [message setThumbImage:[UIImage imageWithData:data]]; 83 | WXMusicObject* musicObject = [WXMusicObject object]; 84 | musicObject.musicUrl =musicUrl; 85 | musicObject.musicDataUrl = musicDataUrl; 86 | message.mediaObject = musicObject; 87 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 88 | req.message = message; 89 | req.bText = NO; 90 | req.scene = type==0?WXSceneSession:WXSceneTimeline; 91 | [WXApi sendReq:req]; 92 | }else if([@"shareVideo" isEqualToString:call.method]){ 93 | NSString* videoUrl= arguments[@"videoUrl"]; 94 | NSString* imgUrl= arguments[@"imgUrl"]; 95 | NSString* videoTitle= arguments[@"title"]; 96 | NSString* videoDescription= arguments[@"description"]; 97 | WXMediaMessage* message =[WXMediaMessage message]; 98 | message.title = videoTitle; 99 | message.description =videoDescription; 100 | NSData* data=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]]; 101 | [message setThumbImage:[UIImage imageWithData:data]]; 102 | WXVideoObject* musicObject = [WXVideoObject object]; 103 | musicObject.videoUrl =videoUrl; 104 | 105 | message.mediaObject = musicObject; 106 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 107 | req.message = message; 108 | req.bText = NO; 109 | req.scene = type==0?WXSceneSession:WXSceneTimeline; 110 | [WXApi sendReq:req]; 111 | }else if([@"login" isEqualToString:call.method]){ 112 | NSString* scope= arguments[@"scope"]; 113 | NSString* state= arguments[@"state"]; 114 | SendAuthReq* req =[[SendAuthReq alloc] init]; 115 | req.scope = scope; 116 | req.state = state; 117 | 118 | //第三方向微信终端发送一个SendAuthReq消息结构 119 | [WXApi sendReq:req]; 120 | }else if([@"pay" isEqualToString:call.method]){ 121 | PayReq *request = [[PayReq alloc] init]; 122 | NSString* partnerId= arguments[@"partnerId"]; 123 | NSString* prepayId= arguments[@"prepayId"]; 124 | NSString* package= arguments[@"package"]; 125 | NSString* nonceStr= arguments[@"nonceStr"]; 126 | NSString* time= arguments[@"timeStamp"]; 127 | NSString* sign= arguments[@"sign"]; 128 | request.partnerId = partnerId; 129 | request.prepayId= prepayId; 130 | request.package = package; 131 | request.nonceStr= nonceStr; 132 | request.timeStamp= [time intValue];; 133 | request.sign = sign; 134 | [WXApi sendReq:request]; 135 | } 136 | } 137 | -(BOOL)handleOpenURL:(NSNotification *)aNotification 138 | { 139 | NSString * aURLString = [aNotification userInfo][@"url"]; 140 | NSURL * aURL = [NSURL URLWithString:aURLString]; 141 | if ([WXApi handleOpenURL:aURL delegate:self]) 142 | { 143 | return YES; 144 | } else { 145 | return NO; 146 | } 147 | 148 | } 149 | 150 | -(void) onResp:(BaseResp*)resp 151 | { 152 | if([resp isKindOfClass:[SendMessageToWXResp class]]) 153 | { 154 | res([NSString stringWithFormat:@"%d",resp.errCode]); 155 | } else if ([resp isKindOfClass:[SendAuthResp class]]) { 156 | SendAuthResp *r = (SendAuthResp *)resp; 157 | if (r.errCode == WXSuccess) 158 | { 159 | res(r.code); 160 | }else{ 161 | res([NSString stringWithFormat:@"%d",r.errCode]); 162 | } 163 | } else if ([resp isKindOfClass:[PayResp class]]) { 164 | res([NSString stringWithFormat:@"%d",resp.errCode]); 165 | } 166 | } 167 | @end 168 | -------------------------------------------------------------------------------- /flutter_wechat.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 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 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/xu/flutterwechat/FlutterWechatPlugin.java: -------------------------------------------------------------------------------- 1 | package com.github.xu.flutterwechat; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.IntentFilter; 7 | import android.graphics.Bitmap; 8 | import android.graphics.BitmapFactory; 9 | import android.os.Handler; 10 | import android.os.Message; 11 | import android.util.Log; 12 | import android.widget.Toast; 13 | 14 | import com.tencent.mm.opensdk.modelbase.BaseReq; 15 | import com.tencent.mm.opensdk.modelbase.BaseResp; 16 | import com.tencent.mm.opensdk.modelmsg.SendAuth; 17 | import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; 18 | import com.tencent.mm.opensdk.modelmsg.WXImageObject; 19 | import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; 20 | import com.tencent.mm.opensdk.modelmsg.WXMusicObject; 21 | import com.tencent.mm.opensdk.modelmsg.WXTextObject; 22 | import com.tencent.mm.opensdk.modelmsg.WXVideoObject; 23 | import com.tencent.mm.opensdk.modelmsg.WXWebpageObject; 24 | import com.tencent.mm.opensdk.modelpay.PayReq; 25 | import com.tencent.mm.opensdk.openapi.IWXAPI; 26 | import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; 27 | import com.tencent.mm.opensdk.openapi.WXAPIFactory; 28 | 29 | import java.io.BufferedInputStream; 30 | import java.io.BufferedOutputStream; 31 | import java.io.ByteArrayOutputStream; 32 | import java.io.IOException; 33 | import java.io.InputStream; 34 | import java.io.OutputStream; 35 | import java.net.HttpURLConnection; 36 | import java.net.URL; 37 | 38 | import io.flutter.plugin.common.EventChannel; 39 | import io.flutter.plugin.common.MethodChannel; 40 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler; 41 | import io.flutter.plugin.common.MethodChannel.Result; 42 | import io.flutter.plugin.common.MethodCall; 43 | import io.flutter.plugin.common.PluginRegistry; 44 | import io.flutter.plugin.common.PluginRegistry.Registrar; 45 | import io.flutter.plugin.common.EventChannel.StreamHandler; 46 | 47 | /** 48 | * FlutterWechatPlugin 49 | */ 50 | public class FlutterWechatPlugin implements MethodCallHandler { 51 | 52 | private static int code;//返回错误吗 53 | private static String loginCode;//获取access_code 54 | private static IWXAPI iwxapi; 55 | private static Result res; 56 | private Context c; 57 | private String wxId; 58 | private Bitmap bitmap; 59 | private WXMediaMessage wxMsg; 60 | private int type = 0; 61 | private final PluginRegistry.Registrar registrar; 62 | private BroadcastReceiver sendRespReceiver; 63 | private Handler mHandler = new Handler(new Handler.Callback() { 64 | 65 | @Override 66 | public boolean handleMessage(Message msg) { 67 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 68 | req.scene = type == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline; 69 | switch (msg.what) { 70 | case 0: 71 | if (bitmap != null) { 72 | wxMsg.setThumbImage(bitmap); 73 | } 74 | req.transaction = String.valueOf(System.currentTimeMillis()); 75 | req.message = wxMsg; 76 | iwxapi.sendReq(req); 77 | break; 78 | case 1: 79 | if (bitmap != null) { 80 | wxMsg.setThumbImage(bitmap); 81 | } else { 82 | Toast.makeText(c, "图片路径错误", Toast.LENGTH_SHORT).show(); 83 | break; 84 | } 85 | WXImageObject wxImageObject = new WXImageObject(bitmap); 86 | wxMsg.mediaObject = wxImageObject; 87 | Bitmap bmp = Bitmap.createScaledBitmap(bitmap, 80, 80, true); 88 | bmp.recycle(); 89 | wxMsg.setThumbImage(bitmap); 90 | req.transaction = String.valueOf(System.currentTimeMillis()); 91 | req.message = wxMsg; 92 | iwxapi.sendReq(req); 93 | break; 94 | case 3: 95 | if (bitmap != null) { 96 | wxMsg.setThumbImage(bitmap); 97 | } 98 | req.transaction = String.valueOf(System.currentTimeMillis()); 99 | req.message = wxMsg; 100 | 101 | iwxapi.sendReq(req); 102 | break; 103 | case 4: 104 | if (bitmap != null) { 105 | wxMsg.setThumbImage(bitmap); 106 | } 107 | req.transaction = String.valueOf(System.currentTimeMillis()); 108 | req.message = wxMsg; 109 | iwxapi.sendReq(req); 110 | break; 111 | default: 112 | break; 113 | } 114 | return false; 115 | } 116 | }); 117 | 118 | public static int getCode() { 119 | 120 | return code; 121 | } 122 | 123 | public static void setCode(int tCode) { 124 | 125 | code = tCode; 126 | } 127 | 128 | public static String getLoginCode() { 129 | return loginCode; 130 | } 131 | 132 | public static void setLoginCode(String tCode) { 133 | 134 | loginCode = tCode; 135 | } 136 | 137 | private FlutterWechatPlugin(Context context, Registrar registrar) { 138 | this.registrar = registrar; 139 | c = context; 140 | } 141 | 142 | /** 143 | * Plugin registration. 144 | */ 145 | public static void registerWith(Registrar registrar) { 146 | final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_wechat"); 147 | final FlutterWechatPlugin instance = new FlutterWechatPlugin(registrar.context(), registrar); 148 | channel.setMethodCallHandler(instance); 149 | IntentFilter intentFilter = new IntentFilter(); 150 | intentFilter.addAction("sendResp"); 151 | registrar.context().registerReceiver(createReceiver(), intentFilter); 152 | } 153 | 154 | 155 | @Override 156 | public void onMethodCall(MethodCall call, Result result) { 157 | res=result; 158 | switch (call.method) { 159 | case "registerWechat": 160 | wxId = call.argument("wxId"); 161 | iwxapi = WXAPIFactory.createWXAPI(c, wxId, true); 162 | iwxapi.registerApp(wxId); 163 | res=result; 164 | res.success(null); 165 | break; 166 | case "shareWebPage": 167 | WXWebpageObject webpage = new WXWebpageObject(); 168 | final String webpageUrl = call.argument("webpageUrl"); 169 | final String webDescription = call.argument("description"); 170 | final String webTitle = call.argument("title"); 171 | type = call.argument("type"); 172 | final String imgUrl = call.argument("imgUrl"); 173 | webpage.webpageUrl = webpageUrl; 174 | wxMsg = new WXMediaMessage(webpage); 175 | wxMsg.title = webTitle; 176 | wxMsg.description = webDescription; 177 | 178 | //网络图片或者本地图片 179 | new Thread() { 180 | public void run() { 181 | Message message = new Message(); 182 | bitmap = GetLocalOrNetBitmap(imgUrl); 183 | message.what = 0; 184 | mHandler.sendMessage(message); 185 | } 186 | }.start(); 187 | 188 | break; 189 | case "shareText": 190 | WXTextObject textObject = new WXTextObject(); 191 | final String text = call.argument("text"); 192 | textObject.text = text; 193 | wxMsg = new WXMediaMessage(); 194 | wxMsg.mediaObject = textObject; 195 | wxMsg.description = text; 196 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 197 | req.transaction = String.valueOf(System.currentTimeMillis()); 198 | req.message = wxMsg; 199 | req.scene = type == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline; 200 | iwxapi.sendReq(req); 201 | break; 202 | case "shareImage": 203 | final String shareImageUrl = call.argument("imgUrl"); 204 | wxMsg = new WXMediaMessage(); 205 | //网络图片或者本地图片 206 | new Thread() { 207 | public void run() { 208 | Message message = new Message(); 209 | bitmap = GetLocalOrNetBitmap(shareImageUrl); 210 | message.what = 1; 211 | mHandler.sendMessage(message); 212 | } 213 | }.start(); 214 | case "shareMusic": 215 | String musicUrl = call.argument("musicUrl"); 216 | final String musicDataUrl = call.argument("musicDataUrl"); 217 | final String musicImgUrl = call.argument("imgUrl"); 218 | final String musicLowBandDataUrl = call.argument("musicLowBandDataUrl"); 219 | final String musicLowBandUrl = call.argument("musicLowBandUrl"); 220 | final String musicDescription = call.argument("description"); 221 | final String musicTitle = call.argument("title"); 222 | WXMusicObject wxMusicObject = new WXMusicObject(); 223 | wxMusicObject.musicUrl = musicUrl; 224 | wxMusicObject.musicDataUrl = musicDataUrl; 225 | wxMusicObject.musicLowBandDataUrl = musicLowBandDataUrl; 226 | wxMusicObject.musicLowBandUrl = musicLowBandUrl; 227 | wxMsg = new WXMediaMessage(); 228 | wxMsg.mediaObject = wxMusicObject; 229 | wxMsg.title = musicTitle; 230 | wxMsg.description = musicDescription; 231 | //网络图片或者本地图片 232 | new Thread() { 233 | public void run() { 234 | Message message = new Message(); 235 | bitmap = GetLocalOrNetBitmap(musicImgUrl); 236 | message.what = 3; 237 | mHandler.sendMessage(message); 238 | } 239 | }.start(); 240 | break; 241 | case "shareVideo": 242 | final String videoImgUrl = call.argument("imgUrl"); 243 | final String videoDescription = call.argument("description"); 244 | final String videoTitle = call.argument("title"); 245 | final String videoUrl = call.argument("videoUrl"); 246 | final String videoLowBandUrl = call.argument("videoLowBandUrl"); 247 | WXVideoObject videoObject = new WXVideoObject(); 248 | videoObject.videoUrl = videoUrl; 249 | videoObject.videoLowBandUrl = videoLowBandUrl; 250 | wxMsg = new WXMediaMessage(videoObject); 251 | wxMsg.description = videoDescription; 252 | wxMsg.title = videoTitle; 253 | 254 | //网络图片或者本地图片 255 | new Thread() { 256 | public void run() { 257 | Message message = new Message(); 258 | bitmap = GetLocalOrNetBitmap(videoImgUrl); 259 | message.what = 4; 260 | mHandler.sendMessage(message); 261 | } 262 | }.start(); 263 | 264 | break; 265 | case "login": 266 | final String scope = call.argument("scope"); 267 | final String state = call.argument("state"); 268 | SendAuth.Req sendReq = new SendAuth.Req(); 269 | sendReq.scope = scope; 270 | sendReq.state = state; 271 | iwxapi.sendReq(sendReq); 272 | break; 273 | case "pay": 274 | final String appId = call.argument("appId"); 275 | final String partnerId = call.argument("partnerId"); 276 | final String prepayId = call.argument("prepayId"); 277 | final String nonceStr = call.argument("nonceStr"); 278 | final String timeStampe = call.argument("timeStamp"); 279 | final String sign = call.argument("sign"); 280 | final String packageValue = call.argument("package"); 281 | PayReq payReq = new PayReq(); 282 | payReq.partnerId = partnerId; 283 | payReq.prepayId = prepayId; 284 | payReq.nonceStr = nonceStr; 285 | payReq.timeStamp = timeStampe; 286 | payReq.sign = sign; 287 | payReq.packageValue = packageValue; 288 | payReq.appId = appId; 289 | iwxapi.sendReq(payReq); 290 | break; 291 | default: 292 | result.notImplemented(); 293 | break; 294 | } 295 | 296 | 297 | } 298 | 299 | public Bitmap GetLocalOrNetBitmap(String url) { 300 | Bitmap bitmap = null; 301 | InputStream in = null; 302 | BufferedOutputStream out = null; 303 | try { 304 | in = new BufferedInputStream(new URL(url).openStream(), 1024); 305 | final ByteArrayOutputStream dataStream = new ByteArrayOutputStream(); 306 | out = new BufferedOutputStream(dataStream, 1024); 307 | copy(in, out); 308 | out.flush(); 309 | byte[] data = dataStream.toByteArray(); 310 | bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); 311 | return bitmap; 312 | } catch (IOException e) { 313 | e.printStackTrace(); 314 | return null; 315 | } 316 | } 317 | 318 | private static void copy(InputStream in, OutputStream out) 319 | throws IOException { 320 | byte[] b = new byte[1024]; 321 | int read; 322 | while ((read = in.read(b)) != -1) { 323 | out.write(b, 0, read); 324 | } 325 | } 326 | 327 | private static BroadcastReceiver createReceiver() { 328 | return new BroadcastReceiver() { 329 | @Override 330 | public void onReceive(Context context, Intent intent) { 331 | System.out.println(intent.getStringExtra("type")); 332 | if (intent.getStringExtra("type").equals("SendAuthResp")) { 333 | res.success(intent.getStringExtra("code")); 334 | } else if (intent.getStringExtra("type").equals("PayResp")) { 335 | res.success(intent.getStringExtra("code")); 336 | } else if (intent.getStringExtra("type").equals("ShareResp")) { 337 | System.out.println(intent.getStringExtra("code")); 338 | res.success(intent.getStringExtra("code")); 339 | } 340 | } 341 | }; 342 | } 343 | } 344 | --------------------------------------------------------------------------------