├── image ├── weixin.png └── url-types.png ├── android ├── libs │ └── wechat-sdk-android-6.8.0.aar ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── theweflex │ │ └── react │ │ ├── WeChatPackage.java │ │ └── WeChatModule.java └── build.gradle ├── ios ├── WechatOpenSDK-XCFramework.xcframework │ ├── ios-arm64_armv7 │ │ ├── libWechatOpenSDK.a │ │ └── Headers │ │ │ ├── WechatAuthSDK.h │ │ │ ├── WXApi.h │ │ │ └── WXApiObject.h │ ├── ios-arm64_i386_x86_64-simulator │ │ ├── libWechatOpenSDK.a │ │ └── Headers │ │ │ ├── WechatAuthSDK.h │ │ │ ├── WXApi.h │ │ │ └── WXApiObject.h │ ├── PrivacyInfo.xcprivacy │ ├── Info.plist │ └── README.txt ├── RCTWeChat.h └── RCTWeChat.m ├── react-native-mwechat.podspec ├── package.json ├── docs ├── handle-extinfo.md ├── build-setup-android.md └── build-setup-ios.md ├── LICENSE ├── .gitignore ├── demo └── App.js ├── index.d.ts ├── README.md └── index.js /image/weixin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bashen1/react-native-mwechat/HEAD/image/weixin.png -------------------------------------------------------------------------------- /image/url-types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bashen1/react-native-mwechat/HEAD/image/url-types.png -------------------------------------------------------------------------------- /android/libs/wechat-sdk-android-6.8.0.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bashen1/react-native-mwechat/HEAD/android/libs/wechat-sdk-android-6.8.0.aar -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_armv7/libWechatOpenSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bashen1/react-native-mwechat/HEAD/ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_armv7/libWechatOpenSDK.a -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_i386_x86_64-simulator/libWechatOpenSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bashen1/react-native-mwechat/HEAD/ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_i386_x86_64-simulator/libWechatOpenSDK.a -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyAccessedAPITypes 6 | 7 | 8 | NSPrivacyAccessedAPIType 9 | NSPrivacyAccessedAPICategoryUserDefaults 10 | NSPrivacyAccessedAPITypeReasons 11 | 12 | CA92.1 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /react-native-mwechat.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = package['name'] 7 | s.version = package['version'] 8 | s.summary = package['description'] 9 | s.description = package['description'] 10 | s.homepage = package['homepage'] 11 | s.license = package['license'] 12 | s.author = package['author'] 13 | s.platform = :ios, "9.0" 14 | s.source = { :git => "https://github.com/bashen1/react-native-mwechat.git", :tag => "master" } 15 | s.source_files = "ios/*.{h,m}" 16 | s.vendored_frameworks = "ios/*.xcframework" 17 | s.requires_arc = true 18 | s.frameworks = 'SystemConfiguration','CoreTelephony' 19 | s.library = 'sqlite3','c++','z' 20 | 21 | s.dependency "React-Core" 22 | 23 | end 24 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | def safeExtGet(prop, fallback) { 4 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 5 | } 6 | 7 | android { 8 | compileSdkVersion safeExtGet('compileSdkVersion', 23) 9 | buildToolsVersion safeExtGet('buildToolsVersion', '23.0.1') 10 | 11 | defaultConfig { 12 | minSdkVersion safeExtGet('minSdkVersion', 16) 13 | targetSdkVersion safeExtGet('targetSdkVersion', 22) 14 | versionCode 1 15 | versionName "1.0" 16 | ndk { 17 | abiFilters "armeabi-v7a", "x86" 18 | } 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | jcenter() 25 | maven { url "$projectDir/../../react-native/android" } 26 | } 27 | } 28 | 29 | dependencies { 30 | api 'com.facebook.react:react-native:+' 31 | api(name:'wechat-sdk-android-6.8.0', ext:'aar') 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-mwechat", 3 | "version": "2.6.2", 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": "https://github.com/bashen1/react-native-mwechat.git" 12 | }, 13 | "keywords": [ 14 | "wechat", 15 | "react-native", 16 | "react", 17 | "react-component", 18 | "ios" 19 | ], 20 | "peerDependencies": { 21 | "react-native": ">=0.60" 22 | }, 23 | "author": "bashen1 ", 24 | "contributors": [ 25 | { 26 | "name": "little-snow-fox", 27 | "email": "fox@sfxh.cc" 28 | } 29 | ], 30 | "license": "MIT", 31 | "bugs": { 32 | "url": "https://github.com/bashen1/react-native-mwechat/issues" 33 | }, 34 | "homepage": "https://github.com/bashen1/react-native-mwechat#readme" 35 | } 36 | -------------------------------------------------------------------------------- /docs/handle-extinfo.md: -------------------------------------------------------------------------------- 1 | # 配置项目处理extInfo信息 2 | 3 | 需要配置完Android与iOS微信的基础上 4 | 5 | ## iOS 6 | 7 | 在 `AppDelegate.mm` 添加微信处理回调,此方法会获取到值传递到模块内的handleLaunchIntent方法,如果在AppDelegate处添加了WXApiDelegate,则模块内的onReq不再触发,但是onResp正常触发 8 | 9 | 如果`AppDelegate.mm`接管onReq,请务必在ReactJs调用`handleLaunchAppReq`,因为有一个状态锁需要打开 10 | 11 | 12 | ## Android 13 | 14 | 调整 `WXEntryActivity.java` 为如下代码,如果没有则新建 15 | 16 | ```java 17 | package your.package.wxapi; 18 | 19 | import android.app.Activity; 20 | import android.os.Bundle; 21 | import com.theweflex.react.WeChatModule; 22 | 23 | public class WXEntryActivity extends Activity { 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | PackageManager packageManager = getPackageManager(); 28 | Intent intent = packageManager.getLaunchIntentForPackage(this.getPackageName()); 29 | startActivity(intent); 30 | // 注意:以下Intent顺序不能调整 31 | WeChatModule.handleIntent(getIntent()); 32 | WeChatModule.handleLaunchIntent(getIntent()); 33 | finish(); 34 | } 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /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 | public class WeChatPackage implements ReactPackage { 14 | @Override 15 | public List createNativeModules(ReactApplicationContext reactContext) { 16 | return Arrays.asList(new NativeModule[]{ 17 | // Modules from third-party 18 | new WeChatModule(reactContext), 19 | }); 20 | } 21 | 22 | public List> createJSModules() { 23 | return Collections.emptyList(); 24 | } 25 | 26 | @Override 27 | public List createViewManagers(ReactApplicationContext reactContext) { 28 | return Collections.emptyList(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 孑愁 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 | -------------------------------------------------------------------------------- /ios/RCTWeChat.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import "WXApi.h" 6 | 7 | // define share type constants 8 | #define RCTWXShareTypeNews @"news" 9 | #define RCTWXShareTypeThumbImageUrl @"thumbImage" 10 | #define RCTWXShareTypeImageUrl @"imageUrl" 11 | #define RCTWXShareTypeImageFile @"imageFile" 12 | #define RCTWXShareTypeImageResource @"imageResource" 13 | #define RCTWXShareTypeText @"text" 14 | #define RCTWXShareTypeVideo @"video" 15 | #define RCTWXShareTypeAudio @"audio" 16 | #define RCTWXShareTypeFile @"file" 17 | 18 | #define RCTWXShareType @"type" 19 | #define RCTWXShareTitle @"title" 20 | #define RCTWXShareDescription @"description" 21 | #define RCTWXShareWebpageUrl @"webpageUrl" 22 | #define RCTWXShareImageUrl @"imageUrl" 23 | 24 | #define RCTWXEventName @"WeChat_Resp" 25 | #define RCTWXEventNameWeChatReq @"WeChat_Req" 26 | 27 | @interface RCTWeChat : NSObject 28 | + (void)onReq:(BaseReq *)req; 29 | + (void)onResp:(BaseResp *)resp; 30 | 31 | @property NSString *appId; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AvailableLibraries 6 | 7 | 8 | HeadersPath 9 | Headers 10 | LibraryIdentifier 11 | ios-arm64_armv7 12 | LibraryPath 13 | libWechatOpenSDK.a 14 | SupportedArchitectures 15 | 16 | arm64 17 | armv7 18 | 19 | SupportedPlatform 20 | ios 21 | 22 | 23 | HeadersPath 24 | Headers 25 | LibraryIdentifier 26 | ios-arm64_i386_x86_64-simulator 27 | LibraryPath 28 | libWechatOpenSDK.a 29 | SupportedArchitectures 30 | 31 | arm64 32 | i386 33 | x86_64 34 | 35 | SupportedPlatform 36 | ios 37 | SupportedPlatformVariant 38 | simulator 39 | 40 | 41 | CFBundlePackageType 42 | XFWK 43 | XCFrameworkFormatVersion 44 | 1.0 45 | 46 | 47 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_armv7/Headers/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 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | enum AuthErrCode { 15 | WechatAuth_Err_Ok = 0, //Auth成功 16 | WechatAuth_Err_NormalErr = -1, //普通错误 17 | WechatAuth_Err_NetworkErr = -2, //网络错误 18 | WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败 19 | WechatAuth_Err_Cancel = -4, //用户取消授权 20 | WechatAuth_Err_Timeout = -5, //超时 21 | }; 22 | 23 | @protocol WechatAuthAPIDelegate 24 | @optional 25 | 26 | - (void)onAuthGotQrcode:(UIImage *)image; //得到二维码 27 | - (void)onQrcodeScanned; //二维码被扫描 28 | - (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode; //成功登录 29 | 30 | @end 31 | 32 | @interface WechatAuthSDK : NSObject{ 33 | NSString *_sdkVersion; 34 | __weak id _delegate; 35 | } 36 | 37 | @property(nonatomic, weak, nullable) id delegate; 38 | @property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号 39 | 40 | /*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调 41 | * 42 | * @param appId 微信开发者ID 43 | * @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同 44 | * @param timeStamp 时间戳 45 | * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔 46 | * @param signature 签名 47 | * @param schemeData 会在扫码后拼在scheme后 48 | * @return 成功返回YES,失败返回NO 49 | 注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。 50 | */ 51 | 52 | - (BOOL)Auth:(NSString *)appId 53 | nonceStr:(NSString *)nonceStr 54 | timeStamp:(NSString *)timeStamp 55 | scope:(NSString *)scope 56 | signature:(NSString *)signature 57 | schemeData:(nullable NSString *)schemeData; 58 | 59 | 60 | /*! @brief 暂停登录请求 61 | * 62 | * @return 成功返回YES,失败返回NO。 63 | */ 64 | - (BOOL)StopAuth; 65 | 66 | @end 67 | 68 | NS_ASSUME_NONNULL_END 69 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_i386_x86_64-simulator/Headers/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 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | enum AuthErrCode { 15 | WechatAuth_Err_Ok = 0, //Auth成功 16 | WechatAuth_Err_NormalErr = -1, //普通错误 17 | WechatAuth_Err_NetworkErr = -2, //网络错误 18 | WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败 19 | WechatAuth_Err_Cancel = -4, //用户取消授权 20 | WechatAuth_Err_Timeout = -5, //超时 21 | }; 22 | 23 | @protocol WechatAuthAPIDelegate 24 | @optional 25 | 26 | - (void)onAuthGotQrcode:(UIImage *)image; //得到二维码 27 | - (void)onQrcodeScanned; //二维码被扫描 28 | - (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode; //成功登录 29 | 30 | @end 31 | 32 | @interface WechatAuthSDK : NSObject{ 33 | NSString *_sdkVersion; 34 | __weak id _delegate; 35 | } 36 | 37 | @property(nonatomic, weak, nullable) id delegate; 38 | @property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号 39 | 40 | /*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调 41 | * 42 | * @param appId 微信开发者ID 43 | * @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同 44 | * @param timeStamp 时间戳 45 | * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔 46 | * @param signature 签名 47 | * @param schemeData 会在扫码后拼在scheme后 48 | * @return 成功返回YES,失败返回NO 49 | 注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。 50 | */ 51 | 52 | - (BOOL)Auth:(NSString *)appId 53 | nonceStr:(NSString *)nonceStr 54 | timeStamp:(NSString *)timeStamp 55 | scope:(NSString *)scope 56 | signature:(NSString *)signature 57 | schemeData:(nullable NSString *)schemeData; 58 | 59 | 60 | /*! @brief 暂停登录请求 61 | * 62 | * @return 成功返回YES,失败返回NO。 63 | */ 64 | - (BOOL)StopAuth; 65 | 66 | @end 67 | 68 | NS_ASSUME_NONNULL_END 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | .DS_Store 106 | .history/ 107 | .vscode/ 108 | .gradle/ -------------------------------------------------------------------------------- /docs/build-setup-android.md: -------------------------------------------------------------------------------- 1 | # Android集成 2 | 3 | 在项目的 `android/build.gradle` 添加如下节点 4 | 5 | ```java 6 | allprojects { 7 | repositories { 8 | mavenCentral() 9 | flatDir { dirs "$rootDir/../node_modules/react-native-mwechat/android/libs" } 10 | } 11 | } 12 | ``` 13 | 14 | ## 集成微信登录与分享 15 | 16 | 如果你需要集成微信的登录与分享功能,需要在主包目录添加 `wxapi` 目录,并在目录下新建一个名为 `WXEntryActivity.java` 的类,内容如下: 17 | 18 | ```java 19 | package your.package.wxapi; 20 | 21 | import android.app.Activity; 22 | import android.os.Bundle; 23 | import com.theweflex.react.WeChatModule; 24 | 25 | public class WXEntryActivity extends Activity { 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | WeChatModule.handleIntent(getIntent()); 30 | finish(); 31 | } 32 | } 33 | ``` 34 | 35 | 在 `AndroidManifest.xml` 添加以下节点 36 | 37 | ```xml 38 | 39 | 40 | 45 | 46 | 47 | ``` 48 | 49 | ## 集成微信支付 50 | 51 | 如果你需要集成微信的登录与分享功能,需要在主包目录添加 `wxapi` 目录,并在目录下新建一个名为 `WXPayEntryActivity.java` 的类,内容如下: 52 | 53 | ```java 54 | package your.package.wxapi; 55 | 56 | import android.app.Activity; 57 | import android.os.Bundle; 58 | import com.theweflex.react.WeChatModule; 59 | 60 | public class WXPayEntryActivity extends Activity { 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | WeChatModule.handleIntent(getIntent()); 65 | finish(); 66 | } 67 | } 68 | ``` 69 | 70 | 在 `AndroidManifest.xml` 中添加以下节点 71 | 72 | ```xml 73 | 74 | 75 | 80 | 81 | 82 | ``` 83 | 84 | 如果遇到安卓App拉起小程序后,小程序无法返回App的情况,需要在AndroidManifest.xml的WXEntryActivity中添加下面这段配置: 85 | 86 | ```xml 87 | android:taskAffinity="your packagename" 88 | android:launchMode="singleTask" 89 | ``` 90 | 91 | 保证跳转后回到你的app的task。 92 | 实际上,我的代码如下: 93 | 94 | ```xml 95 | 96 | 97 | 104 | 105 | 106 | ``` 107 | -------------------------------------------------------------------------------- /docs/build-setup-ios.md: -------------------------------------------------------------------------------- 1 | # iOS集成 2 | 3 | ## 1. Add the following libraries to your "Link Binary with Libraries" in Targets > Build Phases 4 | 5 | - [x] `WebKit.framework` 6 | - [x] `SystemConfiguration.framework` 7 | - [x] `CoreTelephony.framework` 8 | - [x] `libsqlite3.0` 9 | - [x] `libc++` 10 | - [x] `libz` 11 | 12 | Add "URL Schema" as your app id for "URL type" in Targets > info, See the following screenshot for the view on your XCode: 13 | 14 | ![Set URL Schema in XCode](./../image/url-types.png) 15 | 16 | 如果不配置,就无法从微信重新回到APP。 17 | 18 | 在 `Info.plist` 的 `LSApplicationQueriesSchemes` 中添加 `wechat` and `weixin` 19 | 20 | ```xml 21 | LSApplicationQueriesSchemes 22 | 23 | weixin 24 | wechat 25 | weixinULAPI 26 | 27 | ``` 28 | 29 | 如果不配置,因为安全权限问题,苹果会阻止你跳转到微信。 30 | 31 | ## 2. 复制以下内容到 `AppDelegate.m` 32 | 33 | 微信回调方法,如果不配置,分享的时候微信会出现"正在连接",然后直接弹回APP。 34 | 35 | ```objc 36 | - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 37 | return [WXApi handleOpenURL:url delegate:self]; 38 | } 39 | 40 | - (BOOL)application:(UIApplication *)application 41 | continueUserActivity:(NSUserActivity *)userActivity 42 | restorationHandler:(void(^)(NSArray> * __nullable 43 | restorableObjects))restorationHandler { 44 | // 触发回调方法 45 | [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; 46 | return [WXApi handleOpenUniversalLink:userActivity 47 | delegate:self]; 48 | } 49 | ``` 50 | 51 | Universal Links 配置文件, 没使用的话可以忽略。 52 | 53 | ```objc 54 | #import 55 | 56 | // ios 8.x or older 不建议再使用这段配置,所以注释掉 57 | // - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 58 | // sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 59 | // { 60 | // [RCTLinkingManager application:application openURL:url options:options]; 61 | // return [WXApi handleOpenURL:url delegate:self]; 62 | // } 63 | 64 | // ios 9.0+ 65 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 66 | options:(NSDictionary *)options 67 | { 68 | // Triggers a callback event. 69 | // 触发回调事件 70 | [RCTLinkingManager application:application openURL:url options:options]; 71 | return [WXApi handleOpenURL:url delegate:self]; 72 | } 73 | ``` 74 | 75 | ```objc 76 | // 微信回调方法 77 | #pragma mark --微信-- 78 | - (void)onReq:(BaseReq*)req { 79 | [RCTWeChat onReq:req]; 80 | } 81 | 82 | -(void)onResp:(BaseResp*)resp { 83 | [RCTWeChat onResp:resp]; 84 | } 85 | ``` 86 | 87 | **注意:不使用 Universal Links 会导致调用微信支付成功后无法获取回调事件。** 88 | 89 | ## 3. 复制以下内容到 `AppDelegate.h` 90 | 91 | ```objc 92 | #import 93 | #import 94 | #import "WXApi.h" 95 | 96 | @interface AppDelegate : UIResponder 97 | 98 | @property (nonatomic, strong) UIWindow *window; 99 | 100 | @end 101 | ``` 102 | 103 | 主要是需要加上 '#import "WXApi.h"' 和 'WXApiDelegate' 。 104 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/README.txt: -------------------------------------------------------------------------------- 1 | 重要! 2 | SDK2.0.4 3 | 1.增加privacy manifest文件 4 | 2.修复跳微信时可能卡顿的问题 5 | 6 | SDK2.0.2 7 | 1. 优化XCFramework打包方式 8 | 9 | SDK2.0.1 10 | 1. SDK支持XCFramework 11 | 12 | SDK2.0.0 13 | 1. 分享能力支持内容防篡改校验 14 | 15 | SDK1.9.9 16 | 1. 授权登录支持关闭自动授权 17 | 2. 分享支持添加签名,防止篡改 18 | 19 | SDK1.9.7 20 | 1. 适配CocoaPods 21 | 22 | SDK1.9.6 23 | 1. 适配iOS 16,减少读写剪切板 24 | 25 | SDK1.9.4 26 | 1. 修复授权登录取消/拒绝时state字段没有带回 27 | 28 | SDK1.9.3 29 | 1. 新增发起二维码支付能力 30 | 31 | SDK1.9.2 32 | 1. 新增发起企微客服会话能力 33 | 34 | SDK1.9.1 35 | 1. 音乐视频分享类型增加运营H5字段 36 | 37 | SDK1.8.9 38 | 1. 增加音乐视频分享类型 39 | 40 | SDK1.8.8 41 | 1. 增加游戏直播消息类型 42 | 43 | SDK1.8.7.1 44 | 1. 修复Xcode11以下编译不通过 45 | 46 | SDK1.8.7 47 | 1. 修复iPadOS,未安装微信的情况下,因为UA问题无法授权登录 48 | 2. 修复未安装微信的情况下, 适配了UIScene的App因为UIAlertView Crash 49 | 3. 增加Universal Link检测函数 50 | 51 | SDK1.8.6.2 52 | 1. 修改包含"UIWebView"字符的类名 53 | 54 | SDK1.8.6.1 55 | 1.短信授权登录使用的UIWebview切换成WKWebview 56 | 57 | SDK1.8.6 58 | 1. 支持Universal Link拉起微信以及返回App 59 | 2. SDK移除MTA库 60 | 61 | SDK1.8.5 62 | 1. 更换MTA库:取消对剪切板的访问, 防止和其他SDK竞争导致crash 63 | 2. NSMutableArray的MTA分类方法改名,减少命名冲突 64 | 3. 不含支付功能版本移除非税支付和医保支付接口 65 | 4. 分享音乐支持填写歌词和高清封面图 66 | 67 | SDK1.8.4 68 | 1. 调整分享图片大小限制 69 | 2. 新增openBusinessView接口 70 | 71 | SDK1.8.3 72 | 1. SDK增加调起微信刷卡支付接口 73 | 2. SDK增加小程序订阅消息接口 74 | 3. 修复小程序订阅消息接口没有resp的问题 75 | 76 | SDK1.8.2 77 | 1. SDK增加开发票授权 WXInvoiceAuthInsert 78 | 2. SDK增加非税接口 WXNontaxPay 79 | 3. SDK增加医保接口 WXPayInsurance 80 | 4. 更换MTA库 81 | 82 | SDK1.8.1 83 | 1. SDK打开小程序支持指定版本(体验,开发,正式版) 84 | 2. SDK分享小程序支持指定版本(体验,开发,正式版) 85 | 3. SDK支持输出log日志 86 | 87 | SDK1.8.0 88 | 1. SDK支持打开小程序 89 | 2. SDK分享小程序支持shareTicket 90 | 91 | SDK1.7.9 92 | 1. SDK订阅一次性消息 93 | 94 | SDK1.7.8 95 | 1 SDK分享小程序支持大图 96 | 97 | SDK1.7.7 98 | 1 增加SDK分享小程序 99 | 2 增加选择发票接口 100 | 101 | SDK1.7.6 102 | 1. 提高稳定性 103 | 1 修复mta崩溃 104 | 2 新增接口支持开发者关闭mta数据统计上报 105 | 106 | SDK1.7.5 107 | 1. 提高稳定性 108 | 2. 加快registerApp接口启动速度 109 | 110 | SDK1.7.4 111 | 1. 更新支持iOS启用 ATS(App Transport Security) 112 | 2. 需要在工程中链接CFNetwork.framework 113 | 3. 在工程配置中的”Other Linker Flags”中加入”-Objc -all_load” 114 | 115 | SDK1.7.3 116 | 1. 增强稳定性,适配iOS10 117 | 2. 修复小于32K的jpg格式缩略图设置失败的问题 118 | 119 | SDK1.7.2 120 | 1. 修复因CTTeleponyNetworkInfo引起的崩溃问题 121 | 122 | SDK1.7.1 123 | 1. 支持兼容ipv6(提升稳定性) 124 | 2. xCode Version 7.3.1 (7D1014) 编译 125 | 126 | SDK1.7 127 | 1. 支持兼容ipv6 128 | 2. 修复若干问题增强稳定性 129 | 130 | SDK1.6.3 131 | 1. xCode7.2 构建的sdk包。 132 | 2. 请使用xCode7.2进行编译。 133 | 3. 需要在Build Phases中Link Security.framework 134 | 4. 修复若干小问题。 135 | 136 | SDK1.6.2 137 | 1、xCode7.1 构建的sdk包 138 | 2、请使用xCode7.1进行编译 139 | 140 | SDK1.6.1 141 | 1、修复armv7s下,bitcode可能编译不过 142 | 2、解决warning 143 | 144 | SDK1.6 145 | 1、iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。 146 | 受此影响,当你的应用在iOS 9中需要使用微信SDK的相关能力(分享、收藏、支付、登录等)时,需要在“Info.plist”里增加如下代码: 147 | LSApplicationQueriesSchemes 148 | 149 | weixin 150 | 151 | NSAppTransportSecurity 152 | 153 | NSAllowsArbitraryLoads 154 | 155 | 156 | 2、开发者需要在工程中链接上 CoreTelephony.framework 157 | 3、解决bitcode编译不过问题 158 | 159 | SDK1.5 160 | 1、废弃safeSendReq:接口,使用sendReq:即可。 161 | 2、新增+(BOOL) sendAuthReq:(SendAuthReq*) req viewController : (UIViewController*) viewController delegate:(id) delegate; 162 | 支持未安装微信情况下Auth,具体见WXApi.h接口描述 163 | 3、微信开放平台新增了微信模块用户统计功能,便于开发者统计微信功能模块的用户使用和活跃情况。开发者需要在工程中链接上:SystemConfiguration.framework,libz.dylib,libsqlite3.0.dylib。 164 | -------------------------------------------------------------------------------- /demo/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | * @flow 7 | */ 8 | 9 | import React, { Fragment, Component } from 'react'; 10 | import { 11 | TouchableOpacity, 12 | SafeAreaView, 13 | ScrollView, 14 | StyleSheet, 15 | StatusBar, 16 | Platform, 17 | View, 18 | Text, 19 | Alert 20 | } from 'react-native'; 21 | 22 | import { 23 | Header, 24 | Colors 25 | } from 'react-native/Libraries/NewAppScreen'; 26 | 27 | import * as WeChat from 'react-native-mwechat'; 28 | 29 | export default class App extends Component { 30 | shareOptions = { 31 | title: 'playground', 32 | description: '微信分享测试', 33 | thumbImage: 'https://i.loli.net/2019/09/03/62FauzAY37gsEXV.png', 34 | type: 'news', 35 | webpageUrl: 'https://github.com/bashen1/react-native-mwechat' 36 | } 37 | constructor(props) { 38 | super(props); 39 | this.state = { 40 | apiVersion: null, 41 | isWXAppInstalled: false, 42 | wxAppInstallUrl: null, 43 | isWXAppSupportApi: false 44 | } 45 | } 46 | handleOpenApp () { 47 | if (this.state.isWXAppInstalled) { 48 | return WeChat.openWXApp(); 49 | } else { 50 | Alert.alert('没有安装微信,请安装之后重试'); 51 | } 52 | } 53 | handleShareToSession () { 54 | if (this.state.isWXAppInstalled) { 55 | WeChat.shareToSession(this.shareOptions).catch((error) => { 56 | Alert.alert(error.message); 57 | }); 58 | } else { 59 | Alert.alert('没有安装微信,请安装之后重试'); 60 | } 61 | } 62 | handleShareToMoment () { 63 | if (this.state.isWXAppInstalled) { 64 | WeChat.shareToTimeline(this.shareOptions).catch((error) => { 65 | Alert.alert(error.message); 66 | }); 67 | } else { 68 | Alert.alert('没有安装微信,请安装之后重试'); 69 | } 70 | } 71 | async componentDidMount() { 72 | try { 73 | WeChat.registerApp('your wexin AppID'); // Replace with your AppID 74 | this.setState({ 75 | apiVersion: await WeChat.getApiVersion(), 76 | wxAppInstallUrl: Platform.OS === 'ios' ? await WeChat.getWXAppInstallUrl(): null, 77 | isWXAppSupportApi: await WeChat.isWXAppSupportApi(), 78 | isWXAppInstalled: await WeChat.isWXAppInstalled() 79 | }); 80 | } catch (e) { 81 | console.error(e); 82 | } 83 | } 84 | render() { 85 | const { apiVersion } = this.state; 86 | return ( 87 | 88 | 89 | 90 | 93 |
94 | 95 | 96 | 97 | ApiVersion: { apiVersion } 98 | 99 | this.handleOpenApp()}> 100 | 打开微信 101 | 102 | this.handleShareToSession()}> 103 | 分享至微信好友 104 | 105 | this.handleShareToMoment()}> 106 | 分享至朋友圈 107 | 108 | 109 | 110 | 111 | 112 | 113 | ); 114 | } 115 | }; 116 | 117 | const styles = StyleSheet.create({ 118 | scrollView: { 119 | backgroundColor: Colors.lighter 120 | }, 121 | body: { 122 | backgroundColor: Colors.white 123 | }, 124 | sectionContainer: { 125 | marginTop: 32, 126 | paddingHorizontal: 24 127 | }, 128 | highlight: { 129 | fontSize: 24, 130 | fontWeight: '600', 131 | color: Colors.black, 132 | textAlign: 'center' 133 | }, 134 | button: { 135 | flex: 1, 136 | margin: 10, 137 | borderWidth: 1, 138 | borderRadius: 30, 139 | paddingVertical: 12, 140 | alignItems: 'center', 141 | justifyContent: 'center', 142 | borderColor: Colors.black 143 | } 144 | }); 145 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /*! @brief 请求发送场景 2 | * 3 | */ 4 | 5 | enum WXScene { 6 | WXSceneSession = 0, /**< 聊天界面 */ 7 | WXSceneTimeline = 1, /**< 朋友圈 */ 8 | WXSceneFavorite = 2, /**< 收藏 */ 9 | WXSceneSpecifiedSession = 3, /**< 指定联系人 */ 10 | }; 11 | 12 | declare module "react-native-mwechat" { 13 | export function registerApp(appId: string, universalLink?: string): Promise; 14 | export function isWXAppInstalled(): Promise; 15 | export function isWXAppSupportApi(): Promise; 16 | export function getApiVersion(): Promise; 17 | export function openWXApp(): Promise; 18 | export interface AuthResponse { 19 | errCode?: number; 20 | errStr?: string; 21 | openId?: string; 22 | code?: string; 23 | url?: string; 24 | lang?: string; 25 | country?: string; 26 | } 27 | export interface WeChatReq { 28 | type?: string, 29 | errStr?: string, 30 | extMsg?: string, 31 | country?: string, 32 | state?: string, 33 | returnKey?: string 34 | } 35 | export interface WeChatResp { 36 | type?: string, 37 | errStr?: string, 38 | extMsg?: string, 39 | country?: string, 40 | state?: string, 41 | returnKey?: string 42 | } 43 | export function sendAuthRequest( 44 | scope: string | string[], 45 | state?: string 46 | ): Promise; 47 | export interface ShareMetadata { 48 | type: 49 | | "news" 50 | | "text" 51 | | "imageUrl" 52 | | "imageFile" 53 | | "imageResource" 54 | | "video" 55 | | "audio" 56 | | "file"; 57 | thumbImage?: string; 58 | description?: string; 59 | webpageUrl?: string; 60 | imageUrl?: string; 61 | videoUrl?: string; 62 | musicUrl?: string; 63 | filePath?: string; 64 | fileExtension?: string; 65 | } 66 | export interface ShareTextMetadata { 67 | text: string, 68 | scene?: WXScene 69 | } 70 | export interface ShareImageMetadata { 71 | imageUrl: string, 72 | scene?: WXScene 73 | } 74 | export interface ShareMusicMetadata { 75 | musicUrl: string, 76 | musicLowBandUrl?: string, 77 | musicDataUrl?: string, 78 | musicLowBandDataUrl?: string, 79 | title?: string, 80 | description?: string, 81 | thumbImageUrl?: string, 82 | scene?: WXScene 83 | } 84 | export interface ShareVideoMetadata { 85 | videoUrl: string, 86 | videoLowBandUrl?: string, 87 | title?: string, 88 | description?: string, 89 | thumbImageUrl?: string, 90 | scene?: WXScene 91 | } 92 | export interface ShareWebpageMetadata { 93 | webpageUrl: string, 94 | title?: string, 95 | description?: string, 96 | thumbImageUrl?: string, 97 | scene?: WXScene 98 | } 99 | export interface ShareMiniProgramMetadata { 100 | webpageUrl: string, 101 | userName: string, 102 | path?: string, 103 | hdImageUrl?: string, 104 | withShareTicket?: string, 105 | miniProgramType?: number, 106 | title?: string, 107 | description?: string, 108 | thumbImageUrl?: string, 109 | scene?: WXScene 110 | } 111 | export interface LaunchMiniProgramMetadata { 112 | userName: string, 113 | miniProgramType?: number, 114 | path?: string 115 | } 116 | 117 | export interface SubscribeMessageMetadata { 118 | scene?: WXScene, 119 | templateId: string, 120 | reserved?: string 121 | } 122 | 123 | export function shareText( 124 | message: ShareTextMetadata 125 | ): Promise<{ errCode?: number; errStr?: string }>; 126 | export function shareImage( 127 | message: ShareImageMetadata 128 | ): Promise<{ errCode?: number; errStr?: string }>; 129 | export function shareLocalImage( 130 | message: ShareImageMetadata 131 | ): Promise<{ errCode?: number; errStr?: string }>; 132 | export function shareMusic( 133 | message: ShareMusicMetadata 134 | ): Promise<{ errCode?: number; errStr?: string }>; 135 | export function shareVideo( 136 | message: ShareVideoMetadata 137 | ): Promise<{ errCode?: number; errStr?: string }>; 138 | export function shareWebpage( 139 | message: ShareWebpageMetadata 140 | ): Promise<{ errCode?: number; errStr?: string }>; 141 | export function shareMiniProgram( 142 | message: ShareMiniProgramMetadata 143 | ): Promise<{ errCode?: number; errStr?: string }>; 144 | export function launchMiniProgram( 145 | message: LaunchMiniProgramMetadata 146 | ): Promise<{ errCode?: number; errStr?: string }>; 147 | export function subscribeMessage( 148 | message: SubscribeMessageMetadata 149 | ): Promise<{ errCode?: number; errStr?: string }>; 150 | export interface PaymentLoad { 151 | partnerId: string; 152 | prepayId: string; 153 | nonceStr: string; 154 | timeStamp: string; 155 | package: string; 156 | sign: string; 157 | } 158 | export function pay( 159 | payload: PaymentLoad 160 | ): Promise<{ errCode?: number; errStr?: string }>; 161 | 162 | export function openCustomerServiceChat(message: { 163 | corpId: string; 164 | url: string; 165 | }): Promise<{ errCode?: number; errStr?: string }>; 166 | 167 | export function handleLaunchAppReq(): void; 168 | } 169 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_armv7/Headers/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 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | 15 | typedef BOOL(^WXGrantReadPasteBoardPermissionCompletion)(void); 16 | 17 | 18 | #pragma mark - WXApiDelegate 19 | /*! @brief 接收并处理来自微信终端程序的事件消息 20 | * 21 | * 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。 22 | * WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。 23 | */ 24 | @protocol WXApiDelegate 25 | @optional 26 | 27 | /*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果 28 | * 29 | * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 30 | * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 31 | * @param req 具体请求内容,是自动释放的 32 | */ 33 | - (void)onReq:(BaseReq*)req; 34 | 35 | 36 | 37 | /*! @brief 发送一个sendReq后,收到微信的回应 38 | * 39 | * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 40 | * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 41 | * @param resp具体的回应内容,是自动释放的 42 | */ 43 | - (void)onResp:(BaseResp*)resp; 44 | 45 | /* ! @brief 用于在iOS16以及以上系统上,控制OpenSDK是否读取剪切板中微信传递的数据以及读取的时机 46 | * 在iOS16以及以上系统,在SDK需要读取剪切板中微信写入的数据时,会回调该方法。没有实现默认会直接读取微信通过剪切板传递过来的数据 47 | * 注意: 48 | * 1. 只在iOS16以及以上的系统版本上回调; 49 | * 2. 不实现时,OpenSDK会直接调用读取剪切板接口,读取微信传递过来的数据; 50 | * 3. 若实现该方法:开发者需要通过调用completion(), 支持异步,通知SDK允许读取剪切板中微信传递的数据, 51 | * 不调用completion()则代表不授权OpenSDK读取剪切板,会导致收不到onReq:, onResp:回调,无法后续业务流程。请谨慎使用 52 | * 4. 不要长时间持有completion不释放,可能会导致内存泄漏。 53 | */ 54 | - (void)onNeedGrantReadPasteBoardPermissionWithURL:(nonnull NSURL *)openURL completion:(nonnull WXGrantReadPasteBoardPermissionCompletion)completion; 55 | 56 | @end 57 | 58 | #pragma mark - WXApiLogDelegate 59 | 60 | @protocol WXApiLogDelegate 61 | 62 | - (void)onLog:(NSString*)log logLevel:(WXLogLevel)level; 63 | 64 | @end 65 | 66 | 67 | #pragma mark - WXApi 68 | 69 | /*! @brief 微信Api接口函数类 70 | * 71 | * 该类封装了微信终端SDK的所有接口 72 | */ 73 | @interface WXApi : NSObject 74 | 75 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 76 | * 77 | * 需要在每次启动第三方应用程序时调用。 78 | * @attention 请保证在主线程中调用此函数 79 | * @param appid 微信开发者ID 80 | * @param universalLink 微信开发者Universal Link 81 | * @return 成功返回YES,失败返回NO。 82 | */ 83 | + (BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink; 84 | 85 | 86 | /*! @brief 处理旧版微信通过URL启动App时传递的数据 87 | * 88 | * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 89 | * @param url 微信启动第三方应用时传递过来的URL 90 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 91 | * @return 成功返回YES,失败返回NO。 92 | */ 93 | + (BOOL)handleOpenURL:(NSURL *)url delegate:(nullable id)delegate; 94 | 95 | 96 | /*! @brief 处理微信通过Universal Link启动App时传递的数据 97 | * 98 | * 需要在 application:continueUserActivity:restorationHandler:中调用。 99 | * @param userActivity 微信启动第三方应用时系统API传递过来的userActivity 100 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 101 | * @return 成功返回YES,失败返回NO。 102 | */ 103 | + (BOOL)handleOpenUniversalLink:(NSUserActivity *)userActivity delegate:(nullable id)delegate; 104 | 105 | 106 | /*! @brief 检查微信是否已被用户安装 107 | * 108 | * @return 微信已安装返回YES,未安装返回NO。 109 | */ 110 | + (BOOL)isWXAppInstalled; 111 | 112 | 113 | 114 | /*! @brief 判断当前微信的版本是否支持OpenApi 115 | * 116 | * @return 支持返回YES,不支持返回NO。 117 | */ 118 | + (BOOL)isWXAppSupportApi; 119 | 120 | 121 | /*! @brief 判断当前微信的版本是否支持分享微信状态功能 122 | * 123 | * @attention 需在工程LSApplicationQueriesSchemes配置中添加weixinStateAPI 124 | * @return 支持返回YES,不支持返回NO。 125 | */ 126 | + (BOOL)isWXAppSupportStateAPI; 127 | 128 | 129 | #ifndef BUILD_WITHOUT_PAY 130 | /*! @brief 判断当前微信的版本是否支持二维码拉起微信支付 131 | * 132 | * @attention 需在工程LSApplicationQueriesSchemes配置中添加weixinQRCodePayAPI 133 | * @return 支持返回YES,不支持返回NO。 134 | */ 135 | + (BOOL)isWXAppSupportQRCodePayAPI; 136 | 137 | #endif 138 | 139 | 140 | /*! @brief 获取微信的itunes安装地址 141 | * 142 | * @return 微信的安装地址字符串。 143 | */ 144 | + (NSString *)getWXAppInstallUrl; 145 | 146 | 147 | 148 | /*! @brief 获取当前微信SDK的版本号 149 | * 150 | * @return 返回当前微信SDK的版本号 151 | */ 152 | + (NSString *)getApiVersion; 153 | 154 | 155 | 156 | /*! @brief 打开微信 157 | * 158 | * @return 成功返回YES,失败返回NO。 159 | */ 160 | + (BOOL)openWXApp; 161 | 162 | 163 | 164 | /*! @brief 发送请求到微信,等待微信返回onResp 165 | * 166 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型 167 | * SendAuthReq、SendMessageToWXReq、PayReq等。 168 | * @param req 具体的发送请求。 169 | * @param completion 调用结果回调block 170 | */ 171 | + (void)sendReq:(BaseReq *)req completion:(void (^ __nullable)(BOOL success))completion; 172 | 173 | /*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面 174 | * 175 | * 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有 176 | * GetMessageFromWXResp、ShowMessageFromWXResp等。 177 | * @param resp 具体的应答内容 178 | * @param completion 调用结果回调block 179 | */ 180 | + (void)sendResp:(BaseResp*)resp completion:(void (^ __nullable)(BOOL success))completion; 181 | 182 | 183 | /*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp 184 | * 185 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。 186 | * @param req 具体的发送请求。 187 | * @param viewController 当前界面对象。 188 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 189 | * @param completion 调用结果回调block 190 | */ 191 | + (void)sendAuthReq:(SendAuthReq *)req viewController:(UIViewController*)viewController delegate:(nullable id)delegate completion:(void (^ __nullable)(BOOL success))completion; 192 | 193 | 194 | /*! @brief 测试函数,用于排查当前App通过Universal Link方式分享到微信的流程 195 | 注意1: 调用自检函数之前必须要先调用registerApp:universalLink接口, 并确认调用成功 196 | 注意2: 自检过程中会有Log产生,可以先调用startLogByLevel函数,根据Log排查问题 197 | 注意3: 会多次回调block 198 | 注意4: 仅用于新接入SDK时调试使用,请勿在正式环境的调用 199 | * 200 | * 当completion回调的step为WXULCheckStepFinal时,表示检测通过,Universal Link接入成功 201 | * @param completion 回调Block 202 | */ 203 | + (void)checkUniversalLinkReady:(nonnull WXCheckULCompletion)completion; 204 | 205 | 206 | /*! @brief WXApi的成员函数,接受微信的log信息。byBlock 207 | 注意1:SDK会强引用这个block,注意不要导致内存泄漏,注意不要导致内存泄漏 208 | 注意2:调用过一次startLog by block之后,如果再调用一次任意方式的startLoad,会释放上一次logBlock,不再回调上一个logBlock 209 | * 210 | * @param level 打印log的级别 211 | * @param logBlock 打印log的回调block 212 | */ 213 | 214 | + (void)startLogByLevel:(WXLogLevel)level logBlock:(WXLogBolock)logBlock; 215 | 216 | /*! @brief WXApi的成员函数,接受微信的log信息。byDelegate 217 | 注意1:sdk会弱引用这个delegate,这里可加任意对象为代理,不需要与WXApiDelegate同一个对象 218 | 注意2:调用过一次startLog by delegate之后,再调用一次任意方式的startLoad,不会再回调上一个logDelegate对象 219 | * @param level 打印log的级别 220 | * @param logDelegate 打印log的回调代理, 221 | */ 222 | + (void)startLogByLevel:(WXLogLevel)level logDelegate:(id)logDelegate; 223 | 224 | /*! @brief 停止打印log,会清理block或者delegate为空,释放block 225 | * @param 226 | */ 227 | + (void)stopLog; 228 | 229 | @end 230 | 231 | NS_ASSUME_NONNULL_END 232 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_i386_x86_64-simulator/Headers/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 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | 15 | typedef BOOL(^WXGrantReadPasteBoardPermissionCompletion)(void); 16 | 17 | 18 | #pragma mark - WXApiDelegate 19 | /*! @brief 接收并处理来自微信终端程序的事件消息 20 | * 21 | * 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。 22 | * WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。 23 | */ 24 | @protocol WXApiDelegate 25 | @optional 26 | 27 | /*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果 28 | * 29 | * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 30 | * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 31 | * @param req 具体请求内容,是自动释放的 32 | */ 33 | - (void)onReq:(BaseReq*)req; 34 | 35 | 36 | 37 | /*! @brief 发送一个sendReq后,收到微信的回应 38 | * 39 | * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 40 | * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 41 | * @param resp具体的回应内容,是自动释放的 42 | */ 43 | - (void)onResp:(BaseResp*)resp; 44 | 45 | /* ! @brief 用于在iOS16以及以上系统上,控制OpenSDK是否读取剪切板中微信传递的数据以及读取的时机 46 | * 在iOS16以及以上系统,在SDK需要读取剪切板中微信写入的数据时,会回调该方法。没有实现默认会直接读取微信通过剪切板传递过来的数据 47 | * 注意: 48 | * 1. 只在iOS16以及以上的系统版本上回调; 49 | * 2. 不实现时,OpenSDK会直接调用读取剪切板接口,读取微信传递过来的数据; 50 | * 3. 若实现该方法:开发者需要通过调用completion(), 支持异步,通知SDK允许读取剪切板中微信传递的数据, 51 | * 不调用completion()则代表不授权OpenSDK读取剪切板,会导致收不到onReq:, onResp:回调,无法后续业务流程。请谨慎使用 52 | * 4. 不要长时间持有completion不释放,可能会导致内存泄漏。 53 | */ 54 | - (void)onNeedGrantReadPasteBoardPermissionWithURL:(nonnull NSURL *)openURL completion:(nonnull WXGrantReadPasteBoardPermissionCompletion)completion; 55 | 56 | @end 57 | 58 | #pragma mark - WXApiLogDelegate 59 | 60 | @protocol WXApiLogDelegate 61 | 62 | - (void)onLog:(NSString*)log logLevel:(WXLogLevel)level; 63 | 64 | @end 65 | 66 | 67 | #pragma mark - WXApi 68 | 69 | /*! @brief 微信Api接口函数类 70 | * 71 | * 该类封装了微信终端SDK的所有接口 72 | */ 73 | @interface WXApi : NSObject 74 | 75 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 76 | * 77 | * 需要在每次启动第三方应用程序时调用。 78 | * @attention 请保证在主线程中调用此函数 79 | * @param appid 微信开发者ID 80 | * @param universalLink 微信开发者Universal Link 81 | * @return 成功返回YES,失败返回NO。 82 | */ 83 | + (BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink; 84 | 85 | 86 | /*! @brief 处理旧版微信通过URL启动App时传递的数据 87 | * 88 | * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 89 | * @param url 微信启动第三方应用时传递过来的URL 90 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 91 | * @return 成功返回YES,失败返回NO。 92 | */ 93 | + (BOOL)handleOpenURL:(NSURL *)url delegate:(nullable id)delegate; 94 | 95 | 96 | /*! @brief 处理微信通过Universal Link启动App时传递的数据 97 | * 98 | * 需要在 application:continueUserActivity:restorationHandler:中调用。 99 | * @param userActivity 微信启动第三方应用时系统API传递过来的userActivity 100 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 101 | * @return 成功返回YES,失败返回NO。 102 | */ 103 | + (BOOL)handleOpenUniversalLink:(NSUserActivity *)userActivity delegate:(nullable id)delegate; 104 | 105 | 106 | /*! @brief 检查微信是否已被用户安装 107 | * 108 | * @return 微信已安装返回YES,未安装返回NO。 109 | */ 110 | + (BOOL)isWXAppInstalled; 111 | 112 | 113 | 114 | /*! @brief 判断当前微信的版本是否支持OpenApi 115 | * 116 | * @return 支持返回YES,不支持返回NO。 117 | */ 118 | + (BOOL)isWXAppSupportApi; 119 | 120 | 121 | /*! @brief 判断当前微信的版本是否支持分享微信状态功能 122 | * 123 | * @attention 需在工程LSApplicationQueriesSchemes配置中添加weixinStateAPI 124 | * @return 支持返回YES,不支持返回NO。 125 | */ 126 | + (BOOL)isWXAppSupportStateAPI; 127 | 128 | 129 | #ifndef BUILD_WITHOUT_PAY 130 | /*! @brief 判断当前微信的版本是否支持二维码拉起微信支付 131 | * 132 | * @attention 需在工程LSApplicationQueriesSchemes配置中添加weixinQRCodePayAPI 133 | * @return 支持返回YES,不支持返回NO。 134 | */ 135 | + (BOOL)isWXAppSupportQRCodePayAPI; 136 | 137 | #endif 138 | 139 | 140 | /*! @brief 获取微信的itunes安装地址 141 | * 142 | * @return 微信的安装地址字符串。 143 | */ 144 | + (NSString *)getWXAppInstallUrl; 145 | 146 | 147 | 148 | /*! @brief 获取当前微信SDK的版本号 149 | * 150 | * @return 返回当前微信SDK的版本号 151 | */ 152 | + (NSString *)getApiVersion; 153 | 154 | 155 | 156 | /*! @brief 打开微信 157 | * 158 | * @return 成功返回YES,失败返回NO。 159 | */ 160 | + (BOOL)openWXApp; 161 | 162 | 163 | 164 | /*! @brief 发送请求到微信,等待微信返回onResp 165 | * 166 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型 167 | * SendAuthReq、SendMessageToWXReq、PayReq等。 168 | * @param req 具体的发送请求。 169 | * @param completion 调用结果回调block 170 | */ 171 | + (void)sendReq:(BaseReq *)req completion:(void (^ __nullable)(BOOL success))completion; 172 | 173 | /*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面 174 | * 175 | * 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有 176 | * GetMessageFromWXResp、ShowMessageFromWXResp等。 177 | * @param resp 具体的应答内容 178 | * @param completion 调用结果回调block 179 | */ 180 | + (void)sendResp:(BaseResp*)resp completion:(void (^ __nullable)(BOOL success))completion; 181 | 182 | 183 | /*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp 184 | * 185 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。 186 | * @param req 具体的发送请求。 187 | * @param viewController 当前界面对象。 188 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 189 | * @param completion 调用结果回调block 190 | */ 191 | + (void)sendAuthReq:(SendAuthReq *)req viewController:(UIViewController*)viewController delegate:(nullable id)delegate completion:(void (^ __nullable)(BOOL success))completion; 192 | 193 | 194 | /*! @brief 测试函数,用于排查当前App通过Universal Link方式分享到微信的流程 195 | 注意1: 调用自检函数之前必须要先调用registerApp:universalLink接口, 并确认调用成功 196 | 注意2: 自检过程中会有Log产生,可以先调用startLogByLevel函数,根据Log排查问题 197 | 注意3: 会多次回调block 198 | 注意4: 仅用于新接入SDK时调试使用,请勿在正式环境的调用 199 | * 200 | * 当completion回调的step为WXULCheckStepFinal时,表示检测通过,Universal Link接入成功 201 | * @param completion 回调Block 202 | */ 203 | + (void)checkUniversalLinkReady:(nonnull WXCheckULCompletion)completion; 204 | 205 | 206 | /*! @brief WXApi的成员函数,接受微信的log信息。byBlock 207 | 注意1:SDK会强引用这个block,注意不要导致内存泄漏,注意不要导致内存泄漏 208 | 注意2:调用过一次startLog by block之后,如果再调用一次任意方式的startLoad,会释放上一次logBlock,不再回调上一个logBlock 209 | * 210 | * @param level 打印log的级别 211 | * @param logBlock 打印log的回调block 212 | */ 213 | 214 | + (void)startLogByLevel:(WXLogLevel)level logBlock:(WXLogBolock)logBlock; 215 | 216 | /*! @brief WXApi的成员函数,接受微信的log信息。byDelegate 217 | 注意1:sdk会弱引用这个delegate,这里可加任意对象为代理,不需要与WXApiDelegate同一个对象 218 | 注意2:调用过一次startLog by delegate之后,再调用一次任意方式的startLoad,不会再回调上一个logDelegate对象 219 | * @param level 打印log的级别 220 | * @param logDelegate 打印log的回调代理, 221 | */ 222 | + (void)startLogByLevel:(WXLogLevel)level logDelegate:(id)logDelegate; 223 | 224 | /*! @brief 停止打印log,会清理block或者delegate为空,释放block 225 | * @param 226 | */ 227 | + (void)stopLog; 228 | 229 | @end 230 | 231 | NS_ASSUME_NONNULL_END 232 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # React-Native-Mwechat 3 | 4 | [![npm version](https://badge.fury.io/js/react-native-mwechat.svg)](https://badge.fury.io/js/react-native-mwechat) 5 | 6 | ![微信](./image/weixin.png?raw=true) 7 | 8 | [React Native] bridging library that integrates WeChat SDKs: 9 | 10 | - [x] iOS SDK 2.0.4 11 | - [x] Android SDK 6.8.0 12 | 13 | ## 前言 14 | 15 | 首先向各位声明,本库是在 [react-native-wechat-lib](https://github.com/little-snow-fox/react-native-wechat-lib) 基础上进行调整。 16 | 17 | 由于 react-native-wechat-lib 所使用的 WeChat SDK 已经是几年前的版本,考虑到自身使用和其它开发者的需要,最终决定开一个新仓库,提供给新项目使用。 18 | 19 | 最后 20 | 21 | 感谢 [yorkie](https://github.com/yorkie) 和各位开发者为 react-native-wechat 做出的贡献。 22 | 23 | 感谢 [little-snow-fox](https://github.com/little-snow-fox) 和各位开发者为 react-native-wechat-lib 做出的贡献。 24 | 25 | ## 目录 26 | 27 | - [安装](#安装) 28 | - [起步](#起步) 29 | - [API 文档](#API文档) 30 | 31 | ## 安装 32 | 33 | ```sh 34 | npm install react-native-mwechat --save 35 | react-native link react-native-mwechat 36 | ``` 37 | 38 | ## 起步 39 | 40 | - [iOS 安装](./docs/build-setup-ios.md) 41 | - [Android 安装](./docs/build-setup-android.md) 42 | 43 | ## API文档 44 | 45 | 本库支持 `TypeScript`,使用 `Promise` 或 `async/await` 来接收返回。 46 | 47 | 接口名称和参数尽量跟腾讯官网保持一致性,除了嵌套对象变成扁平对象,你可以直接查看腾讯文档来获得更多帮助。 48 | 49 | #### registerApp(appid) 注册 50 | 51 | - `appid` {String} the appid you get from WeChat dashboard 52 | - returns {Boolean} explains if your application is registered done 53 | 54 | This method should be called once globally. 55 | 56 | ```js 57 | import * as WeChat from 'react-native-mwechat'; 58 | 59 | WeChat.registerApp('appid', 'universalLink'); 60 | ``` 61 | 62 | #### isWXAppInstalled() 判断微信是否已安装 63 | 64 | - returns {Boolean} if WeChat is installed. 65 | 66 | Check if the WeChat app is installed on the device. 67 | 68 | #### isWXAppSupportApi() 检查支持情况 69 | 70 | - returns {Boolean} Contains the result. 71 | 72 | Check if wechat support open url. 73 | 74 | #### getApiVersion() 获取API版本号 75 | 76 | - returns {String} Contains the result. 77 | 78 | Get the WeChat SDK api version. 79 | 80 | #### openWXApp() 打开微信 81 | 82 | - returns {Boolean} 83 | 84 | Open the WeChat app from your application. 85 | 86 | #### sendAuthRequest([scope[, state]]) 微信授权登录 87 | 88 | - `scope` {Array|String} Scopes of auth request. 89 | - `state` {String} the state of OAuth2 90 | - returns {Object} 91 | 92 | Send authentication request, and it returns an object with the 93 | following fields: 94 | 95 | | field | type | description | 96 | |---------|--------|-------------------------------------| 97 | | errCode | Number | Error Code | 98 | | errStr | String | Error message if any error occurred | 99 | | openId | String | | 100 | | code | String | Authorization code | 101 | | url | String | The URL string | 102 | | lang | String | The user language | 103 | | country | String | The user country | 104 | 105 | #### ShareText(ShareTextMetadata) 分享文本 106 | 107 | ShareTextMetadata 108 | 109 | | name | type | description | 110 | |---------|--------|----------------------------------| 111 | | text | String | 分享文本 | 112 | | scene | Number | 分享到, 0:会话 1:朋友圈 2:收藏 | 113 | 114 | Return: 115 | 116 | | name | type | description | 117 | |---------|--------|-------------------------------------| 118 | | errCode | Number | 0 if authorization successed | 119 | | errStr | String | Error message if any error occurred | 120 | 121 | ```js 122 | import * as WeChat from 'react-native-mwechat'; 123 | 124 | WeChat.shareText({ 125 | text: 'Text content.', 126 | scene: 0 127 | }) 128 | 129 | ``` 130 | 131 | #### ShareImage(ShareImageMetadata) 分享图片 132 | 133 | ShareImageMetadata 134 | 135 | | name | type | description | 136 | |---------|--------|-------------------------------------| 137 | | imageUrl| String | 图片地址 | 138 | | scene | Number | 分享到, 0:会话 1:朋友圈 2:收藏 | 139 | 140 | Return: 141 | 142 | | name | type | description | 143 | |---------|--------|-------------------------------------| 144 | | errCode | Number | 0 if authorization successed | 145 | | errStr | String | Error message if any error occurred | 146 | 147 | ```js 148 | import * as WeChat from 'react-native-mwechat'; 149 | 150 | WeChat.shareImage({ 151 | imageUrl: 'https://google.com/1.jpg', 152 | scene: 0 153 | }) 154 | 155 | ``` 156 | 157 | #### ShareLocalImage(ShareImageMetadata) 分享本地图片 158 | 159 | ShareImageMetadata 160 | 161 | | name | type | description | 162 | |---------|--------|-------------------------------------| 163 | | imageUrl| String | 图片地址 | 164 | | scene | Number | 分享到, 0:会话 1:朋友圈 2:收藏 | 165 | 166 | Return: 167 | 168 | | name | type | description | 169 | |---------|--------|-------------------------------------| 170 | | errCode | Number | 0 if authorization successed | 171 | | errStr | String | Error message if any error occurred | 172 | 173 | ```js 174 | import * as WeChat from 'react-native-mwechat'; 175 | 176 | WeChat.ShareLocalImage({ 177 | imageUrl: '/sdcard/test.png', 178 | scene: 0 179 | }) 180 | ``` 181 | 182 | 注意:图片路径必须在一个 Public 目录里,例如 Download 目录,否则微信没权限读取这张图片,导致图片发不出去。 183 | 184 | #### ShareMusic(ShareMusicMetadata) 分享音乐 185 | 186 | ShareMusicMetadata 187 | 188 | | name | type | description | 189 | |---------------------|--------|-------------------------------| 190 | | title | String | 标题 | 191 | | description | String | 描述 | 192 | | thumbImageUrl | String | 缩略图地址,本库会自动压缩到32KB | 193 | | musicUrl | String | 音频网页的URL地址 | 194 | | musicLowBandUrl | String | 供低带宽环境下使用的音频网页URL地址 | 195 | | musicDataUrl | String | 音频数据的URL地址 | 196 | | musicLowBandDataUrl | String | 供低带宽环境下使用的音频数据URL地址 | 197 | | scene | Number | 分享到, 0:会话 1:朋友圈 2:收藏 | 198 | 199 | Return: 200 | 201 | | name | type | description | 202 | |---------|--------|-------------------------------------| 203 | | errCode | Number | 0 if authorization successed | 204 | | errStr | String | Error message if any error occurred | 205 | 206 | ```js 207 | import * as WeChat from 'react-native-mwechat'; 208 | 209 | WeChat.shareMusic({ 210 | title: 'Good music.', 211 | musicUrl: 'https://google.com/music.mp3', 212 | thumbImageUrl: 'https://google.com/1.jpg', 213 | scene: 0 214 | }) 215 | 216 | ``` 217 | 218 | #### ShareVideo(ShareVideoMetadata) 分享视频 219 | 220 | ShareVideoMetadata 221 | 222 | | name | type | description | 223 | |---------|--------|-------------------------------------| 224 | | title| String | 标题 | 225 | | description| String | 描述 | 226 | | thumbImageUrl| String | 缩略图地址,本库会自动压缩到32KB | 227 | | videoUrl| String | 视频链接 | 228 | | videoLowBandUrl| String | 供低带宽的环境下使用的视频链接 | 229 | | scene | Number | 分享到, 0:会话 1:朋友圈 2:收藏 | 230 | 231 | Return: 232 | 233 | | name | type | description | 234 | |---------|--------|-------------------------------------| 235 | | errCode | Number | 0 if authorization successed | 236 | | errStr | String | Error message if any error occurred | 237 | 238 | ```js 239 | import * as WeChat from 'react-native-mwechat'; 240 | 241 | WeChat.shareVideo({ 242 | title: 'Interesting video.', 243 | videoUrl: 'https://google.com/music.mp3', 244 | thumbImageUrl: 'https://google.com/1.jpg', 245 | scene: 0 246 | }) 247 | 248 | ``` 249 | 250 | #### ShareWebpage (ShareWebpageMetadata) 分享网页 251 | 252 | ShareWebpageMetadata 253 | 254 | | name | type | description | 255 | |---------|--------|-------------------------------------| 256 | | title| String | 标题 | 257 | | description| String | 描述 | 258 | | thumbImageUrl| String | 缩略图地址,本库会自动压缩到32KB | 259 | | webpageUrl| String | HTML 链接 | 260 | | scene | Number | 分享到, 0:会话 1:朋友圈 2:收藏 | 261 | 262 | Return: 263 | 264 | | name | type | description | 265 | |---------|--------|-------------------------------------| 266 | | errCode | Number | 0 if authorization successed | 267 | | errStr | String | Error message if any error occurred | 268 | 269 | ```js 270 | import * as WeChat from 'react-native-mwechat'; 271 | 272 | WeChat.shareWebpage({ 273 | title: 'Interesting web.', 274 | videoUrl: 'https://google.com/music.mp3', 275 | thumbImageUrl: 'https://google.com/1.jpg', 276 | scene: 0 277 | }) 278 | 279 | ``` 280 | 281 | #### ShareMiniProgram(ShareMiniProgramMetadata) 分享小程序 282 | 283 | ShareMiniProgram 284 | 285 | | name | type | description | 286 | |---------|--------|-------------------------------------| 287 | | title| String | 标题 | 288 | | description| String | 描述 | 289 | | thumbImageUrl| String | 缩略图地址,本库会自动压缩到32KB | 290 | | userName| String | 小程序的 userName,填小程序原始id | 291 | | path| String | 小程序的页面路径 | 292 | | hdImageUrl| String | 小程序新版本的预览图二进制数据,6.5.9及以上版本微信客户端支持 | 293 | | withShareTicket| String | 是否使用带shareTicket的分享 | 294 | | miniProgramType| Number | 小程序的类型,默认正式版,1.8.1及以上版本开发者工具包支持分享开发版和体验版小程序 | 295 | | webpageUrl| String | 兼容低版本的网页链接 | 296 | | scene | Number | 分享到, 0:会话 1:朋友圈 2:收藏 | 297 | 298 | Return: 299 | 300 | | name | type | description | 301 | |---------|--------|-------------------------------------| 302 | | errCode | Number | 0 if authorization successed | 303 | | errStr | String | Error message if any error occurred | 304 | 305 | ```js 306 | import * as WeChat from 'react-native-mwechat'; 307 | 308 | WeChat.shareMiniProgram({ 309 | title: 'Mini program.', 310 | userName: 'gh_d39d10000000', 311 | webpageUrl: 'https://google.com/show.html', 312 | thumbImageUrl: 'https://google.com/1.jpg', 313 | scene: 0 314 | }) 315 | 316 | ``` 317 | 318 | #### LaunchMiniProgram (LaunchMiniProgramMetadata) 跳到小程序 319 | 320 | LaunchMiniProgramMetadata 321 | 322 | | name | type | description | 323 | |---------|--------|-------------------------------------| 324 | | userName| String | 填小程序原始id | 325 | | miniProgramType| Number | 可选打开 开发版,体验版和正式版 | 326 | | path| String | 拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar" | 327 | 328 | Return: 329 | 330 | | name | type | description | 331 | |---------|--------|-------------------------------------| 332 | | errCode | Number | 0 if authorization successed | 333 | | errStr | String | Error message if any error occurred | 334 | 335 | ```js 336 | import * as WeChat from 'react-native-mwechat'; 337 | 338 | WeChat.launchMiniProgram({ 339 | userName: 'gh_d39d10000000', 340 | miniProgramType: 1 341 | }) 342 | 343 | ``` 344 | 345 | #### pay(payload) 支付 346 | 347 | - `payload` {Object} the payment data 348 | - `partnerId` {String} 商家向财付通申请的商家ID 349 | - `prepayId` {String} 预支付订单ID 350 | - `nonceStr` {String} 随机串 351 | - `timeStamp` {String} 时间戳 352 | - `package` {String} 商家根据财付通文档填写的数据和签名 353 | - `sign` {String} 商家根据微信开放平台文档对数据做的签名 354 | - returns {Object} 355 | 356 | Sends request for proceeding payment, then returns an object: 357 | 358 | | name | type | description | 359 | |---------|--------|-------------------------------------| 360 | | errCode | Number | 0 if authorization successed | 361 | | errStr | String | Error message if any error occurred | 362 | 363 | #### subscribeMessage(SubscribeMessageMetadata) 一次性订阅消息 364 | 365 | - returns {Object} 366 | 367 | | name | type | description | 368 | |---------|--------|-------------------------------------| 369 | | scene | Number | 重定向后会带上 scene 参数,开发者可以填 0-10000 的整形值,用来标识订阅场值 | 370 | | templateId | String | 订阅消息模板 ID,在微信开放平台提交应用审核通过后获得 | 371 | | reserved | String | 用于保持请求和回调的状态,授权请后原样带回给第三方。该参数可用于防止 csrf 攻击(跨站请求伪造攻击),建议第三方带上该参数,可设置为简单的随机数加 session 进行校验,开发者可以填写 a-zA-Z0-9 的参数值,最多 128 字节,要求做 urlencode | 372 | 373 | #### openCustomerServiceChat (WXOpenCustomerServiceChat) 拉起微信客服 374 | 375 | | name | type | description | 376 | |---------|--------|-------------------------------------| 377 | | corpId| String | 关联的企业id | 378 | | url| String | 客服url | 379 | 380 | Return: 381 | 382 | | name | type | description | 383 | |---------|--------|-------------------------------------| 384 | | errCode | Number | 0 if authorization successed | 385 | | errStr | String | Error message if any error occurred | 386 | 387 | ```js 388 | import * as WeChat from 'react-native-mwechat'; 389 | 390 | WeChat.openCustomerServiceChat({ 391 | corpId: 'wx123432324', 392 | url: 'https://work.weixin.qq.com/kfid/kfc/123123123' 393 | }) 394 | 395 | ``` 396 | 397 | #### handleLaunchAppReq 获取启动onReq信息(务必在启动后进行调用) 398 | 399 | 为了解决微信唤醒App时原生端先触发,但是ReactJs还未准备好,所以以下项目配置信息会缓存启动的时的数据,等调用handleLaunchAppReq时触发`WeChat_Req` 400 | 401 | 此方法会触发模块的`WeChat_Req`,所以在调用此方法之前需要添加`WeChat_Req`监听 402 | 403 | - [需要配置项目](./docs/handle-extinfo.md) 404 | 405 | ```js 406 | import * as WeChat from 'react-native-mwechat'; 407 | 408 | WeChat.registerApp(config.wechat.appID, config.wechat.universalLink); //需要调用 409 | let _wechatReq = DeviceEventEmitter.addListener('WeChat_Req', req => { 410 | console.log(JSON.stringify(req)); 411 | }); 412 | WeChat.handleLaunchAppReq(); 413 | 414 | _wechatReq?.remove?.(); //销毁时记得移除监听 415 | ``` 416 | 417 | ## License 418 | 419 | MIT 420 | -------------------------------------------------------------------------------- /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 | DeviceEventEmitter.addListener('WeChat_Req', resp => { 17 | emitter.emit(resp.type, resp); 18 | }); 19 | 20 | function wrapRegisterApp(nativeFunc) { 21 | if (!nativeFunc) { 22 | return undefined; 23 | } 24 | return (...args) => { 25 | if (isAppRegistered) { 26 | return Promise.resolve(true); 27 | } 28 | isAppRegistered = true; 29 | return new Promise((resolve, reject) => { 30 | nativeFunc.apply(null, [ 31 | ...args, 32 | (error, result) => { 33 | if (!error) { 34 | return resolve(result); 35 | } 36 | if (typeof error === 'string') { 37 | return reject(new Error(error)); 38 | } 39 | reject(error); 40 | }, 41 | ]); 42 | }); 43 | }; 44 | } 45 | 46 | function wrapApi(nativeFunc) { 47 | if (!nativeFunc) { 48 | return undefined; 49 | } 50 | return (...args) => { 51 | if (!isAppRegistered) { 52 | return Promise.reject(new Error('registerApp required.')); 53 | } 54 | return new Promise((resolve, reject) => { 55 | nativeFunc.apply(null, [ 56 | ...args, 57 | (error, result) => { 58 | if (!error) { 59 | return resolve(result); 60 | } 61 | if (typeof error === 'string') { 62 | return reject(new Error(error)); 63 | } 64 | reject(error); 65 | }, 66 | ]); 67 | }); 68 | }; 69 | } 70 | 71 | /** 72 | * `addListener` inherits from `events` module 73 | * @method addListener 74 | * @param {String} eventName - the event name 75 | * @param {Function} trigger - the function when event is fired 76 | */ 77 | export const addListener = emitter.addListener.bind(emitter); 78 | 79 | /** 80 | * `once` inherits from `events` module 81 | * @method once 82 | * @param {String} eventName - the event name 83 | * @param {Function} trigger - the function when event is fired 84 | */ 85 | export const once = emitter.once.bind(emitter); 86 | 87 | /** 88 | * `removeAllListeners` inherits from `events` module 89 | * @method removeAllListeners 90 | * @param {String} eventName - the event name 91 | */ 92 | export const removeAllListeners = emitter.removeAllListeners.bind(emitter); 93 | 94 | /** 95 | * @method registerApp 96 | * @param {String} appid - the app id 97 | * @return {Promise} 98 | */ 99 | export const registerApp = wrapRegisterApp(WeChat.registerApp); 100 | 101 | // /** 102 | // * @method registerAppWithDescription 103 | // * @param {String} appid - the app id 104 | // * @param {String} appdesc - the app description 105 | // * @return {Promise} 106 | // */ 107 | // export const registerAppWithDescription = wrapRegisterApp( 108 | // WeChat.registerAppWithDescription, 109 | // ); 110 | 111 | /** 112 | * Return if the wechat app is installed in the device. 113 | * @method isWXAppInstalled 114 | * @return {Promise} 115 | */ 116 | export const isWXAppInstalled = wrapApi(WeChat.isWXAppInstalled); 117 | 118 | /** 119 | * Return if the wechat application supports the api 120 | * @method isWXAppSupportApi 121 | * @return {Promise} 122 | */ 123 | export const isWXAppSupportApi = wrapApi(WeChat.isWXAppSupportApi); 124 | 125 | /** 126 | * Get the wechat app installed url 127 | * @method getWXAppInstallUrl 128 | * @return {String} the wechat app installed url 129 | */ 130 | export const getWXAppInstallUrl = wrapApi(WeChat.getWXAppInstallUrl); 131 | 132 | /** 133 | * Get the wechat api version 134 | * @method getApiVersion 135 | * @return {String} the api version string 136 | */ 137 | export const getApiVersion = wrapApi(WeChat.getApiVersion); 138 | 139 | /** 140 | * Open wechat app 141 | * @method openWXApp 142 | * @return {Promise} 143 | */ 144 | export const openWXApp = wrapApi(WeChat.openWXApp); 145 | 146 | // wrap the APIs 147 | const nativeShareToTimeline = wrapApi(WeChat.shareToTimeline); 148 | const nativeLaunchMiniProgram = wrapApi(WeChat.launchMiniProgram); 149 | const nativeShareToSession = wrapApi(WeChat.shareToSession); 150 | const nativeShareToFavorite = wrapApi(WeChat.shareToFavorite); 151 | const nativeSendAuthRequest = wrapApi(WeChat.sendAuthRequest); 152 | const nativeShareText = wrapApi(WeChat.shareText); 153 | const nativeShareImage = wrapApi(WeChat.shareImage); 154 | const nativeShareLocalImage = wrapApi(WeChat.shareLocalImage); 155 | const nativeShareMusic = wrapApi(WeChat.shareMusic); 156 | const nativeShareVideo = wrapApi(WeChat.shareVideo); 157 | const nativeShareWebpage = wrapApi(WeChat.shareWebpage); 158 | const nativeShareMiniProgram = wrapApi(WeChat.shareMiniProgram); 159 | const nativeSubscribeMessage = wrapApi(WeChat.subscribeMessage); 160 | const nativeOpenCustomerServiceChat = wrapApi(WeChat.openCustomerServiceChat); 161 | 162 | 163 | /** 164 | * @method sendAuthRequest 165 | * @param {Array} scopes - the scopes for authentication. 166 | * @return {Promise} 167 | */ 168 | export function sendAuthRequest(scopes, state) { 169 | console.warn('sendAuthRequest') 170 | return new Promise((resolve, reject) => { 171 | WeChat.sendAuthRequest(scopes, state, () => {}); 172 | emitter.once('SendAuth.Resp', resp => { 173 | if (resp.errCode === 0) { 174 | resolve(resp); 175 | } else { 176 | reject(new WechatError(resp)); 177 | } 178 | }); 179 | }); 180 | } 181 | 182 | /** 183 | * Share text 184 | * @method shareText 185 | * @param {Object} data 186 | */ 187 | export function shareText(data) { 188 | if (data && data.scene == null) { 189 | data.scene = 0 190 | } 191 | return new Promise((resolve, reject) => { 192 | nativeShareText(data); 193 | emitter.once('SendMessageToWX.Resp', resp => { 194 | if (resp.errCode === 0) { 195 | resolve(resp); 196 | } else { 197 | reject(new WechatError(resp)); 198 | } 199 | }); 200 | }); 201 | } 202 | 203 | /** 204 | * Share image 205 | * @method shareImage 206 | * @param {Object} data 207 | */ 208 | export function shareImage(data) { 209 | if (data && data.scene == null) { 210 | data.scene = 0 211 | } 212 | return new Promise((resolve, reject) => { 213 | nativeShareImage(data); 214 | emitter.once('SendMessageToWX.Resp', resp => { 215 | if (resp.errCode === 0) { 216 | resolve(resp); 217 | } else { 218 | reject(new WechatError(resp)); 219 | } 220 | }); 221 | }); 222 | } 223 | 224 | /** 225 | * Share local image 226 | * @method shareLocalImage 227 | * @param {Object} data 228 | */ 229 | export function shareLocalImage(data) { 230 | if (data && data.scene == null) { 231 | data.scene = 0 232 | } 233 | return new Promise((resolve, reject) => { 234 | nativeShareLocalImage(data); 235 | emitter.once('SendMessageToWX.Resp', resp => { 236 | if (resp.errCode === 0) { 237 | resolve(resp); 238 | } else { 239 | reject(new WechatError(resp)); 240 | } 241 | }); 242 | }); 243 | } 244 | 245 | /** 246 | * Share music 247 | * @method shareMusic 248 | * @param {Object} data 249 | */ 250 | export function shareMusic(data) { 251 | if (data && data.scene == null) { 252 | data.scene = 0 253 | } 254 | return new Promise((resolve, reject) => { 255 | nativeShareMusic(data); 256 | emitter.once('SendMessageToWX.Resp', resp => { 257 | if (resp.errCode === 0) { 258 | resolve(resp); 259 | } else { 260 | reject(new WechatError(resp)); 261 | } 262 | }); 263 | }); 264 | } 265 | 266 | /** 267 | * Share video 268 | * @method shareVideo 269 | * @param {Object} data 270 | */ 271 | export function shareVideo(data) { 272 | if (data && data.scene == null) { 273 | data.scene = 0 274 | } 275 | return new Promise((resolve, reject) => { 276 | nativeShareVideo(data); 277 | emitter.once('SendMessageToWX.Resp', resp => { 278 | if (resp.errCode === 0) { 279 | resolve(resp); 280 | } else { 281 | reject(new WechatError(resp)); 282 | } 283 | }); 284 | }); 285 | } 286 | 287 | /** 288 | * Share webpage 289 | * @method shareWebpage 290 | * @param {Object} data 291 | */ 292 | export function shareWebpage(data) { 293 | if (data && data.scene == null) { 294 | data.scene = 0 295 | } 296 | return new Promise((resolve, reject) => { 297 | nativeShareWebpage(data); 298 | emitter.once('SendMessageToWX.Resp', resp => { 299 | if (resp.errCode === 0) { 300 | resolve(resp); 301 | } else { 302 | reject(new WechatError(resp)); 303 | } 304 | }); 305 | }); 306 | } 307 | /** 308 | * Share miniProgram 309 | * @method shareMiniProgram 310 | * @param {Object} data 311 | */ 312 | export function shareMiniProgram(data) { 313 | if (data && data.scene == null) { 314 | data.scene = 0 315 | } 316 | if (data && data.miniProgramType == null) { 317 | data.miniProgramType = 0 318 | } 319 | return new Promise((resolve, reject) => { 320 | nativeShareMiniProgram(data); 321 | emitter.once('SendMessageToWX.Resp', resp => { 322 | if (resp.errCode === 0) { 323 | resolve(resp); 324 | } else { 325 | reject(new WechatError(resp)); 326 | } 327 | }); 328 | }); 329 | } 330 | 331 | /** 332 | * 打开小程序 333 | * @method launchMini 334 | * @param 335 | * @param {String} userName - 拉起的小程序的username 336 | * @param {Integer} miniProgramType - 拉起小程序的类型. 0-正式版 1-开发版 2-体验版 337 | * @param {String} path - 拉起小程序页面的可带参路径,不填默认拉起小程序首页 338 | */ 339 | export function launchMiniProgram({userName, miniProgramType = 0, path = ''}) { 340 | return new Promise((resolve, reject) => { 341 | if (miniProgramType !== 0 && miniProgramType !== 1 && miniProgramType !== 2) { 342 | reject(new WechatError({errStr: '拉起小程序的类型不对,0-正式版 1-开发版 2-体验版', errCode: -1})) 343 | return 344 | } 345 | nativeLaunchMiniProgram({userName, miniProgramType, path}); 346 | emitter.once('WXLaunchMiniProgramReq.Resp', resp => { 347 | if (resp.errCode === 0) { 348 | resolve(resp); 349 | } else { 350 | reject(new WechatError(resp)); 351 | } 352 | }); 353 | }); 354 | } 355 | 356 | /** 357 | * 一次性订阅消息 358 | * @method shareVideo 359 | * @param {Object} data 360 | */ 361 | export function subscribeMessage(data) { 362 | if (data && data.scene == null) { 363 | data.scene = 0 364 | } 365 | return new Promise((resolve, reject) => { 366 | nativeSubscribeMessage(data); 367 | emitter.once('WXSubscribeMsgReq.Resp', resp => { 368 | if (resp.errCode === 0) { 369 | resolve(resp); 370 | } else { 371 | reject(new WechatError(resp)); 372 | } 373 | }); 374 | }); 375 | } 376 | 377 | /** 378 | * Share something to favorite 379 | * @method shareToFavorite 380 | * @param {Object} data 381 | * @param {String} data.thumbImage - Thumb image of the message, which can be a uri or a resource id. 382 | * @param {String} data.type - Type of this message. Could be {news|text|imageUrl|imageFile|imageResource|video|audio|file} 383 | * @param {String} data.webpageUrl - Required if type equals news. The webpage link to share. 384 | * @param {String} data.imageUrl - Provide a remote image if type equals image. 385 | * @param {String} data.videoUrl - Provide a remote video if type equals video. 386 | * @param {String} data.musicUrl - Provide a remote music if type equals audio. 387 | * @param {String} data.filePath - Provide a local file if type equals file. 388 | * @param {String} data.fileExtension - Provide the file type if type equals file. 389 | */ 390 | export function shareToFavorite(data) { 391 | return new Promise((resolve, reject) => { 392 | nativeShareToFavorite(data); 393 | emitter.once('SendMessageToWX.Resp', resp => { 394 | if (resp.errCode === 0) { 395 | resolve(resp); 396 | } else { 397 | reject(new WechatError(resp)); 398 | } 399 | }); 400 | }); 401 | } 402 | 403 | /** 404 | * wechat pay 405 | * @param {Object} data 406 | * @param {String} data.partnerId 407 | * @param {String} data.prepayId 408 | * @param {String} data.nonceStr 409 | * @param {String} data.timeStamp 410 | * @param {String} data.package 411 | * @param {String} data.sign 412 | * @returns {Promise} 413 | */ 414 | export function pay(data) { 415 | function correct(actual, fixed) { 416 | if (!data[fixed] && data[actual]) { 417 | data[fixed] = data[actual]; 418 | delete data[actual]; 419 | } 420 | } 421 | correct('prepayid', 'prepayId'); 422 | correct('noncestr', 'nonceStr'); 423 | correct('partnerid', 'partnerId'); 424 | correct('timestamp', 'timeStamp'); 425 | 426 | // FIXME(94cstyles) 427 | // Android requires the type of the timeStamp field to be a string 428 | if (Platform.OS === 'android') data.timeStamp = String(data.timeStamp) 429 | 430 | return new Promise((resolve, reject) => { 431 | WeChat.pay(data, result => { 432 | if (result) reject(result); 433 | }); 434 | emitter.once('PayReq.Resp', resp => { 435 | if (resp.errCode === 0) { 436 | resolve(resp); 437 | } else { 438 | reject(new WechatError(resp)); 439 | } 440 | }); 441 | }); 442 | } 443 | 444 | /** 445 | * 拉起微信客服 446 | * @param {Object} data 447 | * @param {String} data.corpId 448 | * @param {String} data.url 449 | * @returns 450 | */ 451 | export function openCustomerServiceChat(data) { 452 | return new Promise((resolve, reject) => { 453 | nativeOpenCustomerServiceChat(data); 454 | emitter.once('WXOpenCustomerServiceReq.Resp', resp => { 455 | if (resp.errCode === 0) { 456 | resolve(resp); 457 | } else { 458 | reject(new WechatError(resp)); 459 | } 460 | }); 461 | }); 462 | } 463 | 464 | /** 465 | * promises will reject with this error when API call finish with an errCode other than zero. 466 | */ 467 | export class WechatError extends Error { 468 | constructor(resp) { 469 | const message = resp.errStr || resp.errCode.toString(); 470 | super(message); 471 | this.name = 'WechatError'; 472 | this.code = resp.errCode; 473 | 474 | // avoid babel's limition about extending Error class 475 | // https://github.com/babel/babel/issues/3083 476 | if (typeof Object.setPrototypeOf === 'function') { 477 | Object.setPrototypeOf(this, WechatError.prototype); 478 | } else { 479 | this.__proto__ = WechatError.prototype; 480 | } 481 | } 482 | } 483 | 484 | export function handleLaunchAppReq () { 485 | WeChat.handleLaunchAppReq(); 486 | } 487 | -------------------------------------------------------------------------------- /ios/RCTWeChat.m: -------------------------------------------------------------------------------- 1 | // Created by little-snow-fox on 2019-10-9. 2 | 3 | #import 4 | #import 5 | #import 6 | #import 7 | #import "RCTWeChat.h" 8 | #import "WXApiObject.h" 9 | 10 | // Define error messages 11 | #define NOT_REGISTERED (@"registerApp required.") 12 | #define INVOKE_FAILED (@"WeChat API invoke returns false.") 13 | 14 | @implementation RCTWeChat 15 | 16 | @synthesize bridge = _bridge; 17 | static BaseReq *cacheLaunchReq; 18 | static RCTBridge *bridgeCommon; 19 | static bool hasHandleLaunch = false; // 是否执行过handleLaunchAppReq 20 | static NSString *appId = @""; 21 | 22 | RCT_EXPORT_MODULE() 23 | 24 | - (instancetype)init 25 | { 26 | self = [super init]; 27 | 28 | if (self) { 29 | } 30 | 31 | return self; 32 | } 33 | 34 | - (void)dealloc 35 | { 36 | } 37 | 38 | - (dispatch_queue_t)methodQueue 39 | { 40 | bridgeCommon = self.bridge; 41 | return dispatch_get_main_queue(); 42 | } 43 | 44 | + (BOOL)requiresMainQueueSetup { 45 | return YES; 46 | } 47 | 48 | // 获取网络图片的公共方法 49 | - (UIImage *)getImageFromURL:(NSString *)fileURL { 50 | UIImage *result; 51 | NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]; 52 | 53 | result = [UIImage imageWithData:data]; 54 | return result; 55 | } 56 | 57 | // 压缩图片 58 | - (NSData *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength { 59 | // Compress by quality 60 | CGFloat compression = 1; 61 | NSData *data = UIImageJPEGRepresentation(image, compression); 62 | 63 | if (data.length < maxLength) { 64 | return data; 65 | } 66 | 67 | CGFloat max = 1; 68 | CGFloat min = 0; 69 | 70 | for (int i = 0; i < 6; ++i) { 71 | compression = (max + min) / 2; 72 | data = UIImageJPEGRepresentation(image, compression); 73 | 74 | if (data.length < maxLength * 0.9) { 75 | min = compression; 76 | } else if (data.length > maxLength) { 77 | max = compression; 78 | } else { 79 | break; 80 | } 81 | } 82 | 83 | UIImage *resultImage = [UIImage imageWithData:data]; 84 | 85 | if (data.length < maxLength) { 86 | return data; 87 | } 88 | 89 | // Compress by size 90 | NSUInteger lastDataLength = 0; 91 | 92 | while (data.length > maxLength && data.length != lastDataLength) { 93 | lastDataLength = data.length; 94 | CGFloat ratio = (CGFloat)maxLength / data.length; 95 | CGSize size = CGSizeMake((NSUInteger)(resultImage.size.width * sqrtf(ratio)), 96 | (NSUInteger)(resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank 97 | UIGraphicsBeginImageContext(size); 98 | [resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)]; 99 | resultImage = UIGraphicsGetImageFromCurrentImageContext(); 100 | UIGraphicsEndImageContext(); 101 | data = UIImageJPEGRepresentation(resultImage, compression); 102 | } 103 | 104 | if (data.length > maxLength) { 105 | return [self compressImage:resultImage toByte:maxLength]; 106 | } 107 | 108 | return data; 109 | } 110 | 111 | RCT_EXPORT_METHOD(registerApp:(NSString *)appid 112 | :(NSString *)universalLink 113 | :(RCTResponseSenderBlock)callback) { 114 | appId = appid; 115 | callback(@[[WXApi registerApp:appid universalLink:universalLink] ? [NSNull null] : INVOKE_FAILED]); 116 | } 117 | 118 | // RCT_EXPORT_METHOD(registerAppWithDescription:(NSString *)appid 119 | // :(NSString *)appdesc 120 | // :(RCTResponseSenderBlock)callback) 121 | // { 122 | // callback(@[[WXApi registerApp:appid withDescription:appdesc] ? [NSNull null] : INVOKE_FAILED]); 123 | // } 124 | 125 | RCT_EXPORT_METHOD(isWXAppInstalled:(RCTResponseSenderBlock)callback) { 126 | callback(@[[NSNull null], @([WXApi isWXAppInstalled])]); 127 | } 128 | 129 | RCT_EXPORT_METHOD(isWXAppSupportApi:(RCTResponseSenderBlock)callback) { 130 | callback(@[[NSNull null], @([WXApi isWXAppSupportApi])]); 131 | } 132 | 133 | RCT_EXPORT_METHOD(getWXAppInstallUrl:(RCTResponseSenderBlock)callback) { 134 | callback(@[[NSNull null], [WXApi getWXAppInstallUrl]]); 135 | } 136 | 137 | RCT_EXPORT_METHOD(getApiVersion:(RCTResponseSenderBlock)callback) { 138 | callback(@[[NSNull null], [WXApi getApiVersion]]); 139 | } 140 | 141 | RCT_EXPORT_METHOD(openWXApp:(RCTResponseSenderBlock)callback) { 142 | callback(@[([WXApi openWXApp] ? [NSNull null] : INVOKE_FAILED)]); 143 | } 144 | 145 | RCT_EXPORT_METHOD(sendRequest:(NSString *)openid 146 | :(RCTResponseSenderBlock)callback) { 147 | BaseReq *req = [[BaseReq alloc] init]; 148 | 149 | req.openID = openid; 150 | // callback(@[[WXApi sendReq:req] ? [NSNull null] : INVOKE_FAILED]); 151 | void (^ completion)(BOOL); 152 | completion = ^(BOOL success) 153 | { 154 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 155 | return; 156 | }; 157 | [WXApi sendReq:req completion:completion]; 158 | } 159 | 160 | RCT_EXPORT_METHOD(sendAuthRequest:(NSString *)scope 161 | :(NSString *)state 162 | :(RCTResponseSenderBlock)callback) { 163 | SendAuthReq *req = [[SendAuthReq alloc] init]; 164 | 165 | req.scope = scope; 166 | req.state = state; 167 | void (^ completion)(BOOL); 168 | completion = ^(BOOL success) 169 | { 170 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 171 | return; 172 | }; 173 | UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; 174 | [WXApi sendAuthReq:req viewController:rootViewController delegate:self completion:completion]; 175 | } 176 | 177 | RCT_EXPORT_METHOD(sendSuccessResponse:(RCTResponseSenderBlock)callback) { 178 | BaseResp *resp = [[BaseResp alloc] init]; 179 | 180 | resp.errCode = WXSuccess; 181 | void (^ completion)(BOOL); 182 | completion = ^(BOOL success) 183 | { 184 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 185 | return; 186 | }; 187 | [WXApi sendResp:resp completion:completion]; 188 | // callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]); 189 | } 190 | 191 | RCT_EXPORT_METHOD(sendErrorCommonResponse:(NSString *)message 192 | :(RCTResponseSenderBlock)callback) { 193 | BaseResp *resp = [[BaseResp alloc] init]; 194 | 195 | resp.errCode = WXErrCodeCommon; 196 | resp.errStr = message; 197 | void (^ completion)(BOOL); 198 | completion = ^(BOOL success) 199 | { 200 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 201 | return; 202 | }; 203 | [WXApi sendResp:resp completion:completion]; 204 | // callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]); 205 | } 206 | 207 | RCT_EXPORT_METHOD(sendErrorUserCancelResponse:(NSString *)message 208 | :(RCTResponseSenderBlock)callback) { 209 | BaseResp *resp = [[BaseResp alloc] init]; 210 | 211 | resp.errCode = WXErrCodeUserCancel; 212 | resp.errStr = message; 213 | void (^ completion)(BOOL); 214 | completion = ^(BOOL success) 215 | { 216 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 217 | return; 218 | }; 219 | [WXApi sendResp:resp completion:completion]; 220 | // callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]); 221 | } 222 | 223 | // 分享文本 224 | RCT_EXPORT_METHOD(shareText:(NSDictionary *)data 225 | :(RCTResponseSenderBlock)callback) { 226 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 227 | 228 | req.bText = YES; 229 | req.text = data[@"text"]; 230 | req.scene = [data[@"scene"] integerValue]; 231 | void (^ completion)(BOOL); 232 | completion = ^(BOOL success) 233 | { 234 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 235 | return; 236 | }; 237 | [WXApi sendReq:req completion:completion]; 238 | } 239 | 240 | // 分享图片 241 | RCT_EXPORT_METHOD(shareImage:(NSDictionary *)data 242 | :(RCTResponseSenderBlock)callback) { 243 | NSString *imageUrl = data[@"imageUrl"]; 244 | 245 | if (imageUrl == NULL || [imageUrl isEqual:@""]) { 246 | callback([NSArray arrayWithObject:@"shareImage: The value of ImageUrl cannot be empty."]); 247 | return; 248 | } 249 | 250 | NSRange range = [imageUrl rangeOfString:@"."]; 251 | 252 | if (range.length == 0) { 253 | callback([NSArray arrayWithObject:@"shareImage: ImageUrl value, Could not find file suffix."]); 254 | return; 255 | } 256 | 257 | // 根据路径下载图片 258 | UIImage *image = [self getImageFromURL:imageUrl]; 259 | // 从 UIImage 获取图片数据 260 | NSData *imageData = UIImageJPEGRepresentation(image, 1); 261 | // 用图片数据构建 WXImageObject 对象 262 | WXImageObject *imageObject = [WXImageObject object]; 263 | imageObject.imageData = imageData; 264 | 265 | WXMediaMessage *message = [WXMediaMessage message]; 266 | // 利用原图压缩出缩略图,确保缩略图大小不大于32KB 267 | message.thumbData = [self compressImage:image toByte:32678]; 268 | message.mediaObject = imageObject; 269 | message.title = data[@"title"]; 270 | message.description = data[@"description"]; 271 | 272 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 273 | req.bText = NO; 274 | req.message = message; 275 | req.scene = [data[@"scene"] integerValue]; 276 | // [WXApi sendReq:req]; 277 | void (^ completion)(BOOL); 278 | completion = ^(BOOL success) 279 | { 280 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 281 | return; 282 | }; 283 | [WXApi sendReq:req completion:completion]; 284 | } 285 | 286 | // 分享本地图片 287 | RCT_EXPORT_METHOD(shareLocalImage:(NSDictionary *)data 288 | :(RCTResponseSenderBlock)callback) { 289 | NSString *imageUrl = data[@"imageUrl"]; 290 | 291 | if (imageUrl == NULL || [imageUrl isEqual:@""]) { 292 | callback([NSArray arrayWithObject:@"shareLocalImage: The value of ImageUrl cannot be empty."]); 293 | return; 294 | } 295 | 296 | NSRange range = [imageUrl rangeOfString:@"."]; 297 | 298 | if (range.length == 0) { 299 | callback([NSArray arrayWithObject:@"shareLocalImage: ImageUrl value, Could not find file suffix."]); 300 | return; 301 | } 302 | 303 | // 根据路径下载图片 304 | UIImage *image = [UIImage imageWithContentsOfFile:imageUrl]; 305 | // 从 UIImage 获取图片数据 306 | NSData *imageData = UIImageJPEGRepresentation(image, 1); 307 | // 用图片数据构建 WXImageObject 对象 308 | WXImageObject *imageObject = [WXImageObject object]; 309 | imageObject.imageData = imageData; 310 | 311 | WXMediaMessage *message = [WXMediaMessage message]; 312 | // 利用原图压缩出缩略图,确保缩略图大小不大于32KB 313 | message.thumbData = [self compressImage:image toByte:32678]; 314 | message.mediaObject = imageObject; 315 | message.title = data[@"title"]; 316 | message.description = data[@"description"]; 317 | 318 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 319 | req.bText = NO; 320 | req.message = message; 321 | req.scene = [data[@"scene"] integerValue]; 322 | // [WXApi sendReq:req]; 323 | void (^ completion)(BOOL); 324 | completion = ^(BOOL success) 325 | { 326 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 327 | return; 328 | }; 329 | [WXApi sendReq:req completion:completion]; 330 | } 331 | 332 | // 分享音乐 333 | RCT_EXPORT_METHOD(shareMusic:(NSDictionary *)data 334 | :(RCTResponseSenderBlock)callback) { 335 | WXMusicObject *musicObject = [WXMusicObject object]; 336 | 337 | musicObject.musicUrl = data[@"musicUrl"]; 338 | musicObject.musicLowBandUrl = data[@"musicLowBandUrl"]; 339 | musicObject.musicDataUrl = data[@"musicDataUrl"]; 340 | musicObject.musicLowBandDataUrl = data[@"musicLowBandDataUrl"]; 341 | 342 | WXMediaMessage *message = [WXMediaMessage message]; 343 | message.title = data[@"title"]; 344 | message.description = data[@"description"]; 345 | NSString *thumbImageUrl = data[@"thumbImageUrl"]; 346 | 347 | if (thumbImageUrl != NULL && ![thumbImageUrl isEqual:@""]) { 348 | // 根据路径下载图片 349 | UIImage *image = [self getImageFromURL:thumbImageUrl]; 350 | message.thumbData = [self compressImage:image toByte:32678]; 351 | } 352 | 353 | message.mediaObject = musicObject; 354 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 355 | req.bText = NO; 356 | req.message = message; 357 | req.scene = [data[@"scene"] integerValue]; 358 | void (^ completion)(BOOL); 359 | completion = ^(BOOL success) 360 | { 361 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 362 | return; 363 | }; 364 | [WXApi sendReq:req completion:completion]; 365 | } 366 | 367 | // 分享视频 368 | RCT_EXPORT_METHOD(shareVideo:(NSDictionary *)data 369 | :(RCTResponseSenderBlock)callback) { 370 | WXVideoObject *videoObject = [WXVideoObject object]; 371 | 372 | videoObject.videoUrl = data[@"videoUrl"]; 373 | videoObject.videoLowBandUrl = data[@"videoLowBandUrl"]; 374 | WXMediaMessage *message = [WXMediaMessage message]; 375 | message.title = data[@"title"]; 376 | message.description = data[@"description"]; 377 | NSString *thumbImageUrl = data[@"thumbImageUrl"]; 378 | 379 | if (thumbImageUrl != NULL && ![thumbImageUrl isEqual:@""]) { 380 | UIImage *image = [self getImageFromURL:thumbImageUrl]; 381 | message.thumbData = [self compressImage:image toByte:32678]; 382 | } 383 | 384 | message.mediaObject = videoObject; 385 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 386 | req.bText = NO; 387 | req.message = message; 388 | req.scene = [data[@"scene"] integerValue]; 389 | void (^ completion)(BOOL); 390 | completion = ^(BOOL success) 391 | { 392 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 393 | return; 394 | }; 395 | [WXApi sendReq:req completion:completion]; 396 | } 397 | 398 | // 分享网页 399 | RCT_EXPORT_METHOD(shareWebpage:(NSDictionary *)data 400 | :(RCTResponseSenderBlock)callback) { 401 | WXWebpageObject *webpageObject = [WXWebpageObject object]; 402 | 403 | webpageObject.webpageUrl = data[@"webpageUrl"]; 404 | WXMediaMessage *message = [WXMediaMessage message]; 405 | message.title = data[@"title"]; 406 | message.description = data[@"description"]; 407 | NSString *thumbImageUrl = data[@"thumbImageUrl"]; 408 | 409 | if (thumbImageUrl != NULL && ![thumbImageUrl isEqual:@""]) { 410 | UIImage *image = [self getImageFromURL:thumbImageUrl]; 411 | message.thumbData = [self compressImage:image toByte:32678]; 412 | } 413 | 414 | message.mediaObject = webpageObject; 415 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 416 | req.bText = NO; 417 | req.message = message; 418 | req.scene = [data[@"scene"] integerValue]; 419 | void (^ completion)(BOOL); 420 | completion = ^(BOOL success) 421 | { 422 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 423 | return; 424 | }; 425 | [WXApi sendReq:req completion:completion]; 426 | } 427 | 428 | // 分享小程序 429 | RCT_EXPORT_METHOD(shareMiniProgram:(NSDictionary *)data 430 | :(RCTResponseSenderBlock)callback) { 431 | WXMiniProgramObject *object = [WXMiniProgramObject object]; 432 | 433 | object.webpageUrl = data[@"webpageUrl"]; 434 | object.userName = data[@"userName"]; 435 | object.path = data[@"path"]; 436 | NSString *hdImageUrl = data[@"hdImageUrl"]; 437 | 438 | if (hdImageUrl != NULL && ![hdImageUrl isEqual:@""]) { 439 | UIImage *image = [self getImageFromURL:hdImageUrl]; 440 | // 压缩图片到小于128KB 441 | object.hdImageData = [self compressImage:image toByte:131072]; 442 | } 443 | 444 | object.withShareTicket = data[@"withShareTicket"]; 445 | object.miniProgramType = [data[@"miniProgramType"] integerValue]; 446 | WXMediaMessage *message = [WXMediaMessage message]; 447 | message.title = data[@"title"]; 448 | message.description = data[@"description"]; 449 | //兼容旧版本节点的图片,小于32KB,新版本优先 450 | //使用WXMiniProgramObject的hdImageData属性 451 | NSString *thumbImageUrl = data[@"thumbImageUrl"]; 452 | 453 | if (thumbImageUrl != NULL && ![thumbImageUrl isEqual:@""]) { 454 | UIImage *image = [self getImageFromURL:thumbImageUrl]; 455 | message.thumbData = [self compressImage:image toByte:32678]; 456 | } 457 | 458 | message.mediaObject = object; 459 | SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; 460 | req.bText = NO; 461 | req.message = message; 462 | req.scene = [data[@"scene"] integerValue]; 463 | void (^ completion)(BOOL); 464 | completion = ^(BOOL success) 465 | { 466 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 467 | return; 468 | }; 469 | [WXApi sendReq:req completion:completion]; 470 | } 471 | 472 | // 一次性订阅消息 473 | RCT_EXPORT_METHOD(subscribeMessage:(NSDictionary *)data 474 | :(RCTResponseSenderBlock)callback) { 475 | WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init]; 476 | 477 | req.scene = [data[@"scene"] integerValue]; 478 | req.templateId = data[@"templateId"]; 479 | req.reserved = data[@"reserved"]; 480 | void (^ completion)(BOOL); 481 | completion = ^(BOOL success) 482 | { 483 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 484 | return; 485 | }; 486 | [WXApi sendReq:req completion:completion]; 487 | } 488 | 489 | RCT_EXPORT_METHOD(launchMiniProgram:(NSDictionary *)data 490 | :(RCTResponseSenderBlock)callback) { 491 | WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; 492 | 493 | // 拉起的小程序的username 494 | launchMiniProgramReq.userName = data[@"userName"]; 495 | // 拉起小程序页面的可带参路径,不填默认拉起小程序首页 496 | launchMiniProgramReq.path = data[@"path"]; 497 | // 拉起小程序的类型 498 | launchMiniProgramReq.miniProgramType = [data[@"miniProgramType"] integerValue]; 499 | void (^ completion)(BOOL); 500 | completion = ^(BOOL success) 501 | { 502 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 503 | return; 504 | }; 505 | [WXApi sendReq:launchMiniProgramReq completion:completion]; 506 | // BOOL success = [WXApi sendReq:launchMiniProgramReq]; 507 | // callback(@[success ? [NSNull null] : INVOKE_FAILED]); 508 | } 509 | 510 | RCT_EXPORT_METHOD(pay:(NSDictionary *)data 511 | :(RCTResponseSenderBlock)callback) { 512 | PayReq *req = [PayReq new]; 513 | 514 | req.partnerId = data[@"partnerId"]; 515 | req.prepayId = data[@"prepayId"]; 516 | req.nonceStr = data[@"nonceStr"]; 517 | req.timeStamp = [data[@"timeStamp"] unsignedIntValue]; 518 | req.package = data[@"package"]; 519 | req.sign = data[@"sign"]; 520 | void (^ completion)(BOOL); 521 | completion = ^(BOOL success) 522 | { 523 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 524 | return; 525 | }; 526 | [WXApi sendReq:req completion:completion]; 527 | // BOOL success = [WXApi sendReq:req]; 528 | // callback(@[success ? [NSNull null] : INVOKE_FAILED]); 529 | } 530 | 531 | RCT_EXPORT_METHOD(openCustomerServiceChat:(NSDictionary *)data 532 | :(RCTResponseSenderBlock)callback) { 533 | WXOpenCustomerServiceReq *req = [WXOpenCustomerServiceReq new]; 534 | 535 | req.corpid = data[@"corpId"]; 536 | req.url = data[@"url"]; 537 | 538 | void (^ completion)(BOOL); 539 | completion = ^(BOOL success) 540 | { 541 | callback(@[success ? [NSNull null] : INVOKE_FAILED]); 542 | return; 543 | }; 544 | 545 | [WXApi sendReq:req completion:completion]; 546 | } 547 | 548 | RCT_EXPORT_METHOD(handleLaunchAppReq) { 549 | hasHandleLaunch = true; 550 | 551 | if (cacheLaunchReq != nil) { 552 | [RCTWeChat handleOnReq:cacheLaunchReq]; 553 | } 554 | } 555 | 556 | // 处理微信Req,在AppDelegate调用 557 | + (void)handleLaunchIntent:(BaseReq *)req { 558 | cacheLaunchReq = req;//缓存数据 559 | 560 | if (hasHandleLaunch == true) { 561 | [RCTWeChat handleOnReq:req]; 562 | } 563 | } 564 | 565 | + (void)handleOnReq:(BaseReq *)req 566 | { 567 | if ([req isKindOfClass:[LaunchFromWXReq class]]) { 568 | LaunchFromWXReq *launchReq = req; 569 | NSString *appParameter = launchReq.message.messageExt; 570 | NSMutableDictionary *body = @{ 571 | @"errCode": @0 572 | }.mutableCopy; 573 | body[@"type"] = @"LaunchFromWX.Req"; 574 | body[@"lang"] = launchReq.lang; 575 | body[@"country"] = launchReq.country; 576 | body[@"extMsg"] = appParameter; 577 | 578 | [bridgeCommon.eventDispatcher sendDeviceEventWithName:RCTWXEventNameWeChatReq body:body]; 579 | } 580 | 581 | // 未处理过handleLaunchAppReq,不做清除缓存 582 | if (hasHandleLaunch == true) { 583 | cacheLaunchReq = nil; 584 | } 585 | } 586 | 587 | #pragma mark - wx callback 588 | 589 | + (void)onReq:(BaseReq *)req 590 | { 591 | [RCTWeChat handleLaunchIntent:req]; 592 | } 593 | 594 | + (void)onResp:(BaseResp *)resp 595 | { 596 | if ([resp isKindOfClass:[SendMessageToWXResp class]]) { 597 | SendMessageToWXResp *r = (SendMessageToWXResp *)resp; 598 | 599 | NSMutableDictionary *body = @{ 600 | @"errCode": @(r.errCode) 601 | }.mutableCopy; 602 | body[@"errStr"] = r.errStr; 603 | body[@"lang"] = r.lang; 604 | body[@"country"] = r.country; 605 | body[@"type"] = @"SendMessageToWX.Resp"; 606 | [bridgeCommon.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 607 | } else if ([resp isKindOfClass:[SendAuthResp class]]) { 608 | SendAuthResp *r = (SendAuthResp *)resp; 609 | NSMutableDictionary *body = @{ 610 | @"errCode": @(r.errCode) 611 | }.mutableCopy; 612 | body[@"errStr"] = r.errStr; 613 | body[@"state"] = r.state; 614 | body[@"lang"] = r.lang; 615 | body[@"country"] = r.country; 616 | body[@"type"] = @"SendAuth.Resp"; 617 | 618 | if (resp.errCode == WXSuccess) { 619 | if (appId && r) { 620 | // ios第一次获取不到appid会卡死,加个判断OK 621 | [body addEntriesFromDictionary:@{ @"appid": appId, @"code": r.code }]; 622 | [bridgeCommon.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 623 | } 624 | } else { 625 | [bridgeCommon.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 626 | } 627 | } else if ([resp isKindOfClass:[PayResp class]]) { 628 | PayResp *r = (PayResp *)resp; 629 | NSMutableDictionary *body = @{ 630 | @"errCode": @(r.errCode) 631 | }.mutableCopy; 632 | body[@"errStr"] = r.errStr; 633 | body[@"type"] = @(r.type); 634 | body[@"returnKey"] = r.returnKey; 635 | body[@"type"] = @"PayReq.Resp"; 636 | [bridgeCommon.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 637 | } else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) { 638 | WXLaunchMiniProgramResp *r = (WXLaunchMiniProgramResp *)resp; 639 | NSMutableDictionary *body = @{ 640 | @"errCode": @(r.errCode) 641 | }.mutableCopy; 642 | body[@"errStr"] = r.errStr; 643 | body[@"extMsg"] = r.extMsg; 644 | body[@"type"] = @"WXLaunchMiniProgramReq.Resp"; 645 | [bridgeCommon.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 646 | } else if ([resp isKindOfClass:[WXOpenCustomerServiceResp class]]) { 647 | WXOpenCustomerServiceResp *r = (WXOpenCustomerServiceResp *)resp; 648 | NSMutableDictionary *body = @{ 649 | @"errCode": @(r.errCode) 650 | }.mutableCopy; 651 | body[@"errStr"] = r.errStr; 652 | body[@"extMsg"] = r.extMsg; 653 | body[@"type"] = @"WXOpenCustomerServiceReq.Resp"; 654 | [bridgeCommon.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body]; 655 | } 656 | } 657 | 658 | @end 659 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_armv7/Headers/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 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /*! @brief 错误码 15 | * 16 | */ 17 | enum WXErrCode { 18 | WXSuccess = 0, /**< 成功 */ 19 | WXErrCodeCommon = -1, /**< 普通错误类型 */ 20 | WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ 21 | WXErrCodeSentFail = -3, /**< 发送失败 */ 22 | WXErrCodeAuthDeny = -4, /**< 授权失败 */ 23 | WXErrCodeUnsupport = -5, /**< 微信不支持 */ 24 | }; 25 | 26 | 27 | 28 | /*! @brief 请求发送场景 29 | * 30 | */ 31 | enum WXScene { 32 | WXSceneSession = 0, /**< 聊天界面 */ 33 | WXSceneTimeline = 1, /**< 朋友圈 */ 34 | WXSceneFavorite = 2, /**< 收藏 */ 35 | WXSceneSpecifiedSession = 3, /**< 指定联系人 */ 36 | WXSceneState = 4, /**< 状态 */ 37 | }; 38 | 39 | 40 | enum WXAPISupport { 41 | WXAPISupportSession = 0, 42 | }; 43 | 44 | 45 | 46 | /*! @brief 跳转profile类型 47 | * 48 | */ 49 | enum WXBizProfileType { 50 | WXBizProfileType_Normal = 0, //**< 普通公众号 */ 51 | WXBizProfileType_Device = 1, //**< 硬件公众号 */ 52 | }; 53 | 54 | /*! @brief 分享小程序类型 55 | * 56 | */ 57 | typedef NS_ENUM(NSUInteger, WXMiniProgramType) { 58 | WXMiniProgramTypeRelease = 0, //**< 正式版 */ 59 | WXMiniProgramTypeTest = 1, //**< 开发版 */ 60 | WXMiniProgramTypePreview = 2, //**< 体验版 */ 61 | }; 62 | 63 | /*! @brief 跳转mp网页类型 64 | * 65 | */ 66 | enum WXMPWebviewType { 67 | WXMPWebviewType_Ad = 0, /**< 广告网页 **/ 68 | }; 69 | 70 | /*! @brief log的级别 71 | * 72 | */ 73 | typedef NS_ENUM(NSInteger,WXLogLevel) { 74 | WXLogLevelNormal = 0, // 打印日常的日志 75 | WXLogLevelDetail = 1, // 打印详细的日志 76 | }; 77 | 78 | 79 | /*! @brief 打印回调的block 80 | * 81 | */ 82 | typedef void(^WXLogBolock)(NSString *log); 83 | 84 | /*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),检查步骤枚举值 85 | * 86 | * WXULCheckStepParams 参数检测 87 | * WXULCheckStepSystemVersion 当前系统版本检测 88 | * WXULCheckStepWechatVersion 微信客户端版本检测 89 | * WXULCheckStepSDKInnerOperation 微信SDK内部操作检测 90 | * WXULCheckStepLaunchWechat App拉起微信检测 91 | * WXULCheckStepBackToCurrentApp 由微信返回当前App检测 92 | * WXULCheckStepFinal 最终结果 93 | */ 94 | typedef NS_ENUM(NSInteger, WXULCheckStep) 95 | { 96 | WXULCheckStepParams, 97 | WXULCheckStepSystemVersion, 98 | WXULCheckStepWechatVersion, 99 | WXULCheckStepSDKInnerOperation, 100 | WXULCheckStepLaunchWechat, 101 | WXULCheckStepBackToCurrentApp, 102 | WXULCheckStepFinal, 103 | }; 104 | 105 | 106 | #pragma mark - WXCheckULStepResult 107 | 108 | /*! @brief 该类为微信Universal Link检测函数结果类 109 | * 110 | */ 111 | @interface WXCheckULStepResult : NSObject 112 | 113 | /** 是否成功 */ 114 | @property(nonatomic, assign) BOOL success; 115 | /** 当前错误信息 */ 116 | @property(nonatomic, strong) NSString* errorInfo; 117 | /** 修正建议 */ 118 | @property(nonatomic, strong) NSString* suggestion; 119 | 120 | - (instancetype)initWithCheckResult:(BOOL)success errorInfo:(nullable NSString*)errorInfo suggestion:(nullable NSString*)suggestion; 121 | 122 | @end 123 | 124 | 125 | /*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),回调Block 126 | * 127 | * @param step 当前检测步骤 128 | * @param result 检测结果 129 | */ 130 | typedef void(^WXCheckULCompletion)(WXULCheckStep step, WXCheckULStepResult* result); 131 | 132 | 133 | #pragma mark - BaseReq 134 | /*! @brief 该类为微信终端SDK所有请求类的基类 135 | * 136 | */ 137 | @interface BaseReq : NSObject 138 | 139 | /** 请求类型 */ 140 | @property (nonatomic, assign) int type; 141 | /** 由用户微信号和AppID组成的唯一标识,需要校验微信用户是否换号登录时填写*/ 142 | @property (nonatomic, copy) NSString *openID; 143 | 144 | @end 145 | 146 | 147 | 148 | #pragma mark - BaseResp 149 | /*! @brief 该类为微信终端SDK所有响应类的基类 150 | * 151 | */ 152 | @interface BaseResp : NSObject 153 | /** 错误码 */ 154 | @property (nonatomic, assign) int errCode; 155 | /** 错误提示字符串 */ 156 | @property (nonatomic, copy) NSString *errStr; 157 | /** 响应类型 */ 158 | @property (nonatomic, assign) int type; 159 | 160 | @end 161 | 162 | 163 | 164 | #pragma mark - WXMediaMessage 165 | @class WXMediaMessage; 166 | 167 | #ifndef BUILD_WITHOUT_PAY 168 | 169 | #pragma mark - PayReq 170 | /*! @brief 第三方向微信终端发起支付的消息结构体 171 | * 172 | * 第三方向微信终端发起支付的消息结构体,微信终端处理后会向第三方返回处理结果 173 | * @see PayResp 174 | */ 175 | @interface PayReq : BaseReq 176 | 177 | /** 商家向财付通申请的商家id */ 178 | @property (nonatomic, copy) NSString *partnerId; 179 | /** 预支付订单 */ 180 | @property (nonatomic, copy) NSString *prepayId; 181 | /** 随机串,防重发 */ 182 | @property (nonatomic, copy) NSString *nonceStr; 183 | /** 时间戳,防重发 */ 184 | @property (nonatomic, assign) UInt32 timeStamp; 185 | /** 商家根据财付通文档填写的数据和签名 */ 186 | @property (nonatomic, copy) NSString *package; 187 | /** 商家根据微信开放平台文档对数据做的签名 */ 188 | @property (nonatomic, copy) NSString *sign; 189 | 190 | @end 191 | 192 | 193 | #pragma mark - PayResp 194 | /*! @brief 微信终端返回给第三方的关于支付结果的结构体 195 | * 196 | * 微信终端返回给第三方的关于支付结果的结构体 197 | */ 198 | @interface PayResp : BaseResp 199 | 200 | /** 财付通返回给商家的信息 */ 201 | @property (nonatomic, copy) NSString *returnKey; 202 | 203 | @end 204 | 205 | #pragma mark - WXOfflinePay 206 | /*! @brief 第三方向微信终端发起离线支付 207 | * 208 | * 第三方向微信终端发起离线支付的消息结构体 209 | */ 210 | @interface WXOfflinePayReq : BaseReq 211 | 212 | @end 213 | 214 | /*! @brief 第三方向微信终端发起离线支付返回 215 | * 216 | * 第三方向微信终端发起离线支付返回的消息结构体 217 | */ 218 | @interface WXOfflinePayResp : BaseResp 219 | 220 | @end 221 | 222 | 223 | #pragma mark - WXNontaxPayReq 224 | @interface WXNontaxPayReq:BaseReq 225 | 226 | @property (nonatomic, copy) NSString *urlString; 227 | 228 | @end 229 | 230 | #pragma mark - WXNontaxPayResp 231 | @interface WXNontaxPayResp : BaseResp 232 | 233 | @property (nonatomic, copy) NSString *wxOrderId; 234 | 235 | @end 236 | 237 | #pragma mark - WXPayInsuranceReq 238 | @interface WXPayInsuranceReq : BaseReq 239 | 240 | @property (nonatomic, copy) NSString *urlString; 241 | 242 | @end 243 | 244 | #pragma mark - WXPayInsuranceResp 245 | @interface WXPayInsuranceResp : BaseResp 246 | 247 | @property (nonatomic, copy) NSString *wxOrderId; 248 | 249 | @end 250 | 251 | 252 | #pragma mark - WXQRCodePayReq 253 | @interface WXQRCodePayReq : BaseReq 254 | /** 码内容 255 | * @note 必填,码长度必须大于0且小于10K 256 | */ 257 | @property (nonatomic, copy) NSString *codeContent; 258 | /** 额外信息 259 | * @note 长度必须大于0且小于10K 260 | */ 261 | @property (nonatomic, copy) NSString *extraMsg; 262 | 263 | @end 264 | 265 | @interface WXQRCodePayResp : BaseResp 266 | @end 267 | 268 | #endif 269 | 270 | 271 | #pragma mark - SendAuthReq 272 | /*! @brief 第三方程序向微信终端请求认证的消息结构 273 | * 274 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, 275 | * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 276 | * @see SendAuthResp 277 | */ 278 | @interface SendAuthReq : BaseReq 279 | /** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 280 | * @see SendAuthResp 281 | * @note scope字符串长度不能超过1K 282 | */ 283 | @property (nonatomic, copy) NSString *scope; 284 | /** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 285 | * @note state字符串长度不能超过1K 286 | */ 287 | @property (nonatomic, copy) NSString *state; 288 | 289 | @property (nonatomic, assign) BOOL isOption1; 290 | 291 | /** 是否关闭自动授权 292 | * @note YES为关闭自动授权,每次登陆都需要用户手动授权;NO为允许自动授权 293 | */ 294 | @property (nonatomic, assign) BOOL nonautomatic; 295 | 296 | @property (nonatomic, copy) NSString *extData; 297 | 298 | @end 299 | 300 | #pragma mark - SendAuthResp 301 | /*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 302 | * 303 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 304 | * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 305 | * @see onResp 306 | */ 307 | @interface SendAuthResp : BaseResp 308 | @property (nonatomic, copy, nullable) NSString *code; 309 | /** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 310 | * @note state字符串长度不能超过1K 311 | * @note 在复杂度较高的应用程序中,可能会出现其他模块请求的响应对象被错误地回调到当前模块。 312 | * 为了避免影响其他模块,建议当前模块的开发者根据SendAuthResp的内容,采用白名单的方式进行处理。 313 | * 例如,SendAuthResp.state符合预期时,才对其进行处理。 314 | */ 315 | @property (nonatomic, copy, nullable) NSString *state; 316 | @property (nonatomic, copy, nullable) NSString *lang; 317 | @property (nonatomic, copy, nullable) NSString *country; 318 | @end 319 | 320 | #pragma mark - WXStateJumpInfo 321 | /*! @brief 状态发表时的小尾巴跳转信息 322 | */ 323 | @interface WXStateJumpInfo : NSObject 324 | 325 | @end 326 | 327 | #pragma mark - WXStateJumpUrlInfo 328 | /*! @brief 状态小尾巴跳转指定url的信息 329 | */ 330 | @interface WXStateJumpUrlInfo : WXStateJumpInfo 331 | /** 跳转到指定的url 332 | * @note 必填,url长度必须大于0且小于10K 333 | */ 334 | @property (nonatomic, copy) NSString *url; 335 | 336 | @end 337 | 338 | #pragma mark - WXStateJumpWXMiniProgramInfo 339 | /*! @brief 状态小尾巴跳转指定小程序的信息 340 | */ 341 | @interface WXStateJumpMiniProgramInfo : WXStateJumpInfo 342 | /** 小程序username 343 | * @note 必填 344 | */ 345 | @property (nonatomic, copy) NSString *username; 346 | 347 | /** 小程序页面的路径 348 | * @attention 不填默认拉起小程序首页 349 | */ 350 | @property (nonatomic, copy, nullable) NSString *path; 351 | 352 | /** 分享小程序的版本 353 | * @attention (正式,开发,体验) 354 | */ 355 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; 356 | 357 | @end 358 | 359 | 360 | 361 | #pragma mark - WXStateJumpWXMiniProgramInfo 362 | /*! @brief 状态小尾巴跳转指定视频号主页信息 363 | */ 364 | @interface WXStateJumpChannelProfileInfo : WXStateJumpInfo 365 | /** 视频号username 366 | * @note 必填,username长度必须大于0且小于1K 367 | */ 368 | @property (nonatomic, copy) NSString *username; 369 | 370 | 371 | @end 372 | 373 | #pragma mark - WXStateSceneDataObject 374 | /*! @brief 场景类型额外参数基类 375 | */ 376 | @interface WXSceneDataObject : NSObject 377 | 378 | @end 379 | 380 | #pragma mark - WXStateSceneDataObject 381 | /*! @brief 状态场景类型 382 | * 用户填写WXStateSceneDataObject参数后,可以跳转到微信状态发表页 383 | */ 384 | @interface WXStateSceneDataObject : WXSceneDataObject 385 | 386 | /** 状态标志的ID 387 | * @note 选填,文本长度必须小于10K 388 | */ 389 | @property (nonatomic, copy) NSString *stateId; 390 | /** 状态发表时附带的文本描述 391 | * @note 选填,文本长度必须小于10K 392 | */ 393 | @property (nonatomic, copy) NSString *stateTitle; 394 | /** 后台校验token 395 | * @note 选填,文本长度必须小于10K 396 | */ 397 | @property (nonatomic, copy) NSString *token; 398 | /** 小尾巴跳转所需的信息 399 | * @note 必填,目前仅支持url跳转 400 | */ 401 | @property (nonatomic, strong) WXStateJumpInfo *stateJumpDataInfo; 402 | 403 | @end 404 | 405 | #pragma mark - SendMessageToWXReq 406 | /*! @brief 第三方程序发送消息至微信终端程序的消息结构体 407 | * 408 | * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, 409 | * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 410 | * @see SendMessageToWXResp 411 | */ 412 | @interface SendMessageToWXReq : BaseReq 413 | /** 发送消息的文本内容 414 | * @note 文本长度必须大于0且小于10K 415 | */ 416 | @property (nonatomic, copy) NSString *text; 417 | /** 发送消息的多媒体内容 418 | * @see WXMediaMessage 419 | */ 420 | @property (nonatomic, strong) WXMediaMessage *message; 421 | /** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 422 | @property (nonatomic, assign) BOOL bText; 423 | /** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 424 | * @see WXScene 425 | */ 426 | @property (nonatomic, assign) int scene; 427 | /** 指定发送消息的人 428 | * @note WXSceneSpecifiedSession时有效 429 | */ 430 | @property (nonatomic, copy, nullable) NSString *toUserOpenId; 431 | /** 目标场景附带信息 432 | * @note 目前只针对状态场景 433 | */ 434 | @property (nonatomic, strong) WXSceneDataObject *sceneDataObject; 435 | 436 | @end 437 | 438 | #pragma mark - SendMessageToWXResp 439 | /*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 440 | * 441 | * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 442 | */ 443 | @interface SendMessageToWXResp : BaseResp 444 | @property(nonatomic, copy) NSString *lang; 445 | @property(nonatomic, copy) NSString *country; 446 | @end 447 | 448 | #pragma mark - GetMessageFromWXReq 449 | /*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 450 | * 451 | * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, 452 | * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 453 | */ 454 | @interface GetMessageFromWXReq : BaseReq 455 | @property (nonatomic, strong) NSString *lang; 456 | @property (nonatomic, strong) NSString *country; 457 | @end 458 | 459 | 460 | 461 | #pragma mark - GetMessageFromWXResp 462 | /*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 463 | * 464 | * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 465 | */ 466 | @interface GetMessageFromWXResp : BaseResp 467 | /** 向微信终端提供的文本内容 468 | @note 文本长度必须大于0且小于10K 469 | */ 470 | @property (nonatomic, strong) NSString *text; 471 | /** 向微信终端提供的多媒体内容。 472 | * @see WXMediaMessage 473 | */ 474 | @property (nonatomic, strong) WXMediaMessage *message; 475 | /** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 476 | @property (nonatomic, assign) BOOL bText; 477 | @end 478 | 479 | 480 | 481 | #pragma mark - ShowMessageFromWXReq 482 | /*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 483 | * 484 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 485 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 486 | */ 487 | @interface ShowMessageFromWXReq : BaseReq 488 | /** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 489 | * @see WXMediaMessage 490 | */ 491 | @property (nonatomic, strong) WXMediaMessage *message; 492 | @property (nonatomic, copy) NSString *lang; 493 | @property (nonatomic, copy) NSString *country; 494 | @end 495 | 496 | 497 | 498 | #pragma mark - ShowMessageFromWXResp 499 | /*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 500 | * 501 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 502 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 503 | */ 504 | @interface ShowMessageFromWXResp : BaseResp 505 | @end 506 | 507 | 508 | #pragma mark - LaunchFromWXReq 509 | /*! @brief 微信终端打开第三方程序携带的消息结构体 510 | * 511 | * 微信向第三方发送的结构体,第三方不需要返回 512 | */ 513 | @interface LaunchFromWXReq : BaseReq 514 | @property (nonatomic, strong) WXMediaMessage *message; 515 | @property (nonatomic, copy) NSString *lang; 516 | @property (nonatomic, copy) NSString *country; 517 | @end 518 | 519 | 520 | #pragma mark - OpenWebviewReq 521 | /* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 522 | * 523 | * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 524 | */ 525 | @interface OpenWebviewReq : BaseReq 526 | /** 需要打开的网页对应的Url 527 | * @attention 长度不能超过1024 528 | */ 529 | @property(nonatomic, copy) NSString *url; 530 | 531 | @end 532 | 533 | #pragma mark - OpenWebviewResp 534 | /*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 535 | * 536 | * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 537 | */ 538 | @interface OpenWebviewResp : BaseResp 539 | 540 | @end 541 | 542 | 543 | 544 | #pragma mark - WXOpenBusinessWebViewReq 545 | /*! @brief 第三方通知微信启动内部浏览器,打开指定业务的网页 546 | * 547 | * 548 | */ 549 | @interface WXOpenBusinessWebViewReq : BaseReq 550 | 551 | /** 网页业务类型 552 | * @attention 553 | */ 554 | @property (nonatomic, assign) UInt32 businessType; 555 | 556 | /** 网页业务参数 557 | * @attention 558 | */ 559 | @property (nonatomic, strong, nullable) NSDictionary *queryInfoDic; 560 | 561 | @end 562 | 563 | #pragma mark - WXOpenBusinessWebViewResp 564 | /*! @brief 微信终端向第三方程序返回的WXOpenBusinessWebViewResp处理结果。 565 | * 566 | * 第三方程序向微信终端发送WXOpenBusinessWebViewReq后,微信发送回来的处理结果,该结果用WXOpenBusinessWebViewResp表示。 567 | */ 568 | @interface WXOpenBusinessWebViewResp : BaseResp 569 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 570 | * @attention 长度不能超过2k 571 | */ 572 | @property (nonatomic, copy) NSString *result; 573 | 574 | /** 网页业务类型 575 | * @attention 576 | */ 577 | @property (nonatomic, assign) UInt32 businessType; 578 | 579 | @end 580 | 581 | 582 | #pragma mark - OpenRankListReq 583 | /* ! @brief 第三方通知微信,打开硬件排行榜 584 | * 585 | * 第三方通知微信,打开硬件排行榜 586 | */ 587 | @interface OpenRankListReq : BaseReq 588 | 589 | @end 590 | 591 | #pragma mark - OpenRanklistResp 592 | /*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 593 | * 594 | * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 595 | */ 596 | @interface OpenRankListResp : BaseResp 597 | 598 | @end 599 | 600 | 601 | #pragma mark - WXCardItem 602 | 603 | @interface WXCardItem : NSObject 604 | /** 卡id 605 | * @attention 长度不能超过1024字节 606 | */ 607 | @property (nonatomic, copy) NSString *cardId; 608 | /** ext信息 609 | * @attention 长度不能超过2024字节 610 | */ 611 | @property (nonatomic, copy, nullable) NSString *extMsg; 612 | /** 613 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 614 | */ 615 | @property (nonatomic, assign) UInt32 cardState; 616 | /** 617 | * @attention req不需要填,chooseCard返回的。 618 | */ 619 | @property (nonatomic, copy) NSString *encryptCode; 620 | /** 621 | * @attention req不需要填,chooseCard返回的。 622 | */ 623 | @property (nonatomic, copy) NSString *appID; 624 | @end; 625 | 626 | #pragma mark - WXInvoiceItem 627 | 628 | @interface WXInvoiceItem : NSObject 629 | /** 卡id 630 | * @attention 长度不能超过1024字节 631 | */ 632 | @property (nonatomic, copy) NSString *cardId; 633 | /** ext信息 634 | * @attention 长度不能超过2024字节 635 | */ 636 | @property (nonatomic, copy, nullable) NSString *extMsg; 637 | /** 638 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 639 | */ 640 | @property (nonatomic, assign) UInt32 cardState; 641 | /** 642 | * @attention req不需要填,chooseCard返回的。 643 | */ 644 | @property (nonatomic, copy) NSString *encryptCode; 645 | /** 646 | * @attention req不需要填,chooseCard返回的。 647 | */ 648 | @property (nonatomic, copy) NSString *appID; 649 | 650 | @end 651 | 652 | #pragma mark - AddCardToWXCardPackageReq 653 | /* ! @brief 请求添加卡券至微信卡包 654 | * 655 | */ 656 | 657 | @interface AddCardToWXCardPackageReq : BaseReq 658 | /** 卡列表 659 | * @attention 个数不能超过40个 类型WXCardItem 660 | */ 661 | @property (nonatomic, strong) NSArray *cardAry; 662 | 663 | @end 664 | 665 | 666 | #pragma mark - AddCardToWXCardPackageResp 667 | /** ! @brief 微信返回第三方添加卡券结果 668 | * 669 | */ 670 | 671 | @interface AddCardToWXCardPackageResp : BaseResp 672 | /** 卡列表 673 | * @attention 个数不能超过40个 类型WXCardItem 674 | */ 675 | @property (nonatomic, strong) NSArray *cardAry; 676 | @end 677 | 678 | #pragma mark - WXChooseCardReq 679 | /* ! @brief 请求从微信选取卡券 680 | * 681 | */ 682 | 683 | @interface WXChooseCardReq : BaseReq 684 | @property (nonatomic, copy) NSString *appID; 685 | @property (nonatomic, assign) UInt32 shopID; 686 | @property (nonatomic, assign) UInt32 canMultiSelect; 687 | @property (nonatomic, copy) NSString *cardType; 688 | @property (nonatomic, copy) NSString *cardTpID; 689 | @property (nonatomic, copy) NSString *signType; 690 | @property (nonatomic, copy) NSString *cardSign; 691 | @property (nonatomic, assign) UInt32 timeStamp; 692 | @property (nonatomic, copy) NSString *nonceStr; 693 | @end 694 | 695 | 696 | #pragma mark - WXChooseCardResp 697 | /** ! @brief 微信返回第三方请求选择卡券结果 698 | * 699 | */ 700 | 701 | @interface WXChooseCardResp : BaseResp 702 | @property (nonatomic, strong ) NSArray* cardAry; 703 | @end 704 | 705 | 706 | #pragma mark - WXChooseInvoiceReq 707 | /* ! @brief 请求从微信选取发票 708 | * 709 | */ 710 | @interface WXChooseInvoiceReq : BaseReq 711 | @property (nonatomic, copy) NSString *appID; 712 | @property (nonatomic, assign) UInt32 shopID; 713 | @property (nonatomic, copy) NSString *signType; 714 | @property (nonatomic, copy) NSString *cardSign; 715 | @property (nonatomic, assign) UInt32 timeStamp; 716 | @property (nonatomic, copy) NSString *nonceStr; 717 | @end 718 | 719 | #pragma mark - WXChooseInvoiceResp 720 | /** ! @brief 微信返回第三方请求选择发票结果 721 | * 722 | */ 723 | @interface WXChooseInvoiceResp : BaseResp 724 | @property (nonatomic, strong) NSArray* cardAry; 725 | @end 726 | 727 | #pragma mark - WXSubscriptionReq 728 | @interface WXSubscribeMsgReq : BaseReq 729 | @property (nonatomic, assign) UInt32 scene; 730 | @property (nonatomic, copy) NSString *templateId; 731 | @property (nonatomic, copy, nullable) NSString *reserved; 732 | @end 733 | 734 | #pragma mark - WXSubscriptionReq 735 | @interface WXSubscribeMsgResp : BaseResp 736 | 737 | @property (nonatomic, copy) NSString *templateId; 738 | @property (nonatomic, assign) UInt32 scene; 739 | @property (nonatomic, copy) NSString *action; 740 | @property (nonatomic, copy) NSString *reserved; 741 | @property (nonatomic, copy, nullable) NSString *openId; 742 | 743 | @end 744 | 745 | #pragma mark - WXSubscribeMiniProgramMsg 746 | /** ! @brief 第三方请求订阅小程序消息 747 | * 748 | */ 749 | @interface WXSubscribeMiniProgramMsgReq : BaseReq 750 | @property (nonatomic, copy) NSString *miniProgramAppid; 751 | @end 752 | 753 | #pragma mark - WXSubscriptionReq 754 | @interface WXSubscribeMiniProgramMsgResp : BaseResp 755 | 756 | @property(nonatomic, copy) NSString *openId; // 小程序openid 757 | @property(nonatomic, copy) NSString *unionId; // unionId 758 | @property(nonatomic, copy) NSString *nickName; // 用户昵称 759 | 760 | @end 761 | 762 | #pragma mark - WXinvoiceAuthInsertReq 763 | @interface WXInvoiceAuthInsertReq : BaseReq 764 | 765 | @property (nonatomic, copy) NSString *urlString; 766 | 767 | @end 768 | 769 | #pragma mark - WXinvoiceAuthInsertResp 770 | 771 | @interface WXInvoiceAuthInsertResp : BaseResp 772 | 773 | @property (nonatomic, copy) NSString *wxOrderId; 774 | 775 | @end 776 | 777 | #pragma mark - WXMediaMessage 778 | 779 | /*! @brief 多媒体消息结构体 780 | * 781 | * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 782 | */ 783 | @interface WXMediaMessage : NSObject 784 | 785 | + (WXMediaMessage *)message; 786 | 787 | /** 标题 788 | * @note 长度不能超过512字节 789 | */ 790 | @property (nonatomic, copy) NSString *title; 791 | /** 描述内容 792 | * @note 长度不能超过1K 793 | */ 794 | @property (nonatomic, copy) NSString *description; 795 | /** 缩略图数据 796 | * @note 大小不能超过64K 797 | */ 798 | @property (nonatomic, strong, nullable) NSData *thumbData; 799 | /** 800 | * @note 长度不能超过64字节 801 | */ 802 | @property (nonatomic, copy, nullable) NSString *mediaTagName; 803 | /** 804 | * 805 | */ 806 | @property (nonatomic, copy, nullable) NSString *messageExt; 807 | @property (nonatomic, copy, nullable) NSString *messageAction; 808 | /** 809 | * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 810 | */ 811 | @property (nonatomic, strong) id mediaObject; 812 | 813 | /** 缩略图的hash值 814 | * @note 使用sha256得到,用于计算签名 815 | */ 816 | @property (nonatomic, copy, nullable) NSString *thumbDataHash; 817 | 818 | /** 消息签名 819 | * @note 用于校验消息体是否被篡改过 820 | */ 821 | @property (nonatomic, copy, nullable) NSString *msgSignature; 822 | 823 | 824 | /*! @brief 设置消息缩略图的方法 825 | * 826 | * @param image 缩略图 827 | * @note 大小不能超过256K 828 | */ 829 | - (void)setThumbImage:(UIImage *)image; 830 | 831 | @end 832 | 833 | 834 | 835 | #pragma mark - WXImageObject 836 | /*! @brief 多媒体消息中包含的图片数据对象 837 | * 838 | * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 839 | * @note imageData成员不能为空 840 | * @see WXMediaMessage 841 | */ 842 | @interface WXImageObject : NSObject 843 | /*! @brief 返回一个WXImageObject对象 844 | * 845 | * @note 返回的WXImageObject对象是自动释放的 846 | */ 847 | + (WXImageObject *)object; 848 | 849 | /** 图片真实数据内容 850 | * @note 大小不能超过25M 851 | */ 852 | @property (nonatomic, strong) NSData *imageData; 853 | 854 | /** 图片数据的hash值 855 | * @note 使用sha256得到,用于计算签名 856 | */ 857 | @property (nonatomic, copy, nullable) NSString *imgDataHash; 858 | 859 | /** 分享的图片消息是否要带小程序入口,若 'entranceMiniProgramUsername' 非空则显示 860 | * 仅部分小程序类目可用 861 | * @note 本字段为空则发送普通app图片消息 862 | */ 863 | @property (nonatomic, copy, nullable) NSString *entranceMiniProgramUsername; 864 | 865 | /** 分享的图片消息显示的小程序入口可以跳转的小程序路径 866 | * 仅当 'entranceMiniProgramUsername' 非空时生效 867 | */ 868 | @property (nonatomic, copy, nullable) NSString *entranceMiniProgramPath; 869 | 870 | @end 871 | 872 | 873 | #pragma mark - WXMusicObject 874 | /*! @brief 多媒体消息中包含的音乐数据对象 875 | * 876 | * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 877 | * @note musicUrl和musicLowBandUrl成员不能同时为空。 878 | * @see WXMediaMessage 879 | */ 880 | @interface WXMusicObject : NSObject 881 | /*! @brief 返回一个WXMusicObject对象 882 | * 883 | * @note 返回的WXMusicObject对象是自动释放的 884 | */ 885 | + (WXMusicObject *)object; 886 | 887 | /** 音乐网页的url地址 888 | * @note 长度不能超过10K 889 | */ 890 | @property (nonatomic, copy) NSString *musicUrl; 891 | /** 音乐lowband网页的url地址 892 | * @note 长度不能超过10K 893 | */ 894 | @property (nonatomic, copy) NSString *musicLowBandUrl; 895 | /** 音乐数据url地址 896 | * @note 长度不能超过10K 897 | */ 898 | @property (nonatomic, copy) NSString *musicDataUrl; 899 | 900 | /**音乐lowband数据url地址 901 | * @note 长度不能超过10K 902 | */ 903 | @property (nonatomic, copy) NSString *musicLowBandDataUrl; 904 | 905 | /**音乐封面图Url 906 | * @note 长度不能超过10K 907 | */ 908 | @property (nonatomic, copy) NSString *songAlbumUrl; 909 | 910 | /**歌词信息 LRC格式 911 | * @note 长度不能超过32K 912 | */ 913 | @property (nonatomic, copy, nullable) NSString *songLyric; 914 | @end 915 | 916 | 917 | 918 | #pragma mark - WXMusicVideoObject 919 | 920 | @interface WXMusicVipInfo : NSObject 921 | 922 | /**付费歌曲的id 923 | * @note 长度不能超过32K 924 | */ 925 | @property (nonatomic, copy) NSString *musicId; 926 | 927 | @end 928 | 929 | 930 | @interface WXMusicVideoObject : NSObject 931 | 932 | /*! @brief 返回一个WXMusicVideoObject对象 933 | * 934 | * @note 返回的WXMusicVideoObject对象是自动释放的 935 | */ 936 | + (WXMusicVideoObject *)object; 937 | 938 | /** 音乐网页的url地址 939 | * @note 长度不能超过10K,不能为空 940 | */ 941 | @property (nonatomic, copy) NSString *musicUrl; 942 | 943 | /** 音乐数据url地址 944 | * @note 长度不能超过10K,不能为空 945 | */ 946 | @property (nonatomic, copy) NSString *musicDataUrl; 947 | 948 | /**歌手名 949 | * @note 长度不能超过1k,不能为空 950 | */ 951 | @property (nonatomic, copy) NSString *singerName; 952 | 953 | /** 954 | * @note 音乐时长, 单位毫秒 955 | */ 956 | @property (nonatomic, assign) UInt32 duration; 957 | 958 | /**歌词信息 LRC格式 959 | * @note 长度不能超过32K 960 | */ 961 | @property (nonatomic, copy) NSString *songLyric; 962 | 963 | /**高清封面图 964 | * @note 大小不能超过1M 965 | */ 966 | @property (nonatomic, strong) NSData *hdAlbumThumbData; 967 | 968 | /** 高清封面图数据的hash值 969 | * @note 使用sha256得到,用于计算签名 970 | */ 971 | @property (nonatomic, copy, nullable) NSString *hdAlbumThumbFileHash; 972 | 973 | /**音乐专辑名称 974 | * @note 长度不能超过1k 975 | */ 976 | @property (nonatomic, copy, nullable) NSString *albumName; 977 | 978 | /**音乐流派 979 | * @note 长度不能超过1k 980 | */ 981 | @property (nonatomic, copy, nullable) NSString *musicGenre; 982 | 983 | /**发行时间 984 | * @note Unix时间戳,单位为秒 985 | */ 986 | @property (nonatomic, assign) UInt64 issueDate; 987 | 988 | /**音乐标识符 989 | * @note 长度不能超过1K,从微信跳回应用时会带上 990 | */ 991 | @property (nonatomic, copy, nullable) NSString *identification; 992 | 993 | /**运营H5地址 994 | * @note 选填,建议填写,用户进入歌曲详情页将展示内嵌的运营H5,可展示该歌曲的相关评论、歌曲推荐等内容,不可诱导下载、分享等。 995 | */ 996 | @property (nonatomic, copy, nullable) NSString *musicOperationUrl; 997 | 998 | /** 付费歌曲相关信息 999 | * @note 选填,如果歌曲是需要付费的,那么将付费歌曲id等信息封装在内。 1000 | */ 1001 | @property (nonatomic, strong) WXMusicVipInfo *musicVipInfo; 1002 | 1003 | @end 1004 | 1005 | 1006 | 1007 | #pragma mark - WXVideoObject 1008 | /*! @brief 多媒体消息中包含的视频数据对象 1009 | * 1010 | * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 1011 | * @note videoUrl和videoLowBandUrl不能同时为空。 1012 | * @see WXMediaMessage 1013 | */ 1014 | @interface WXVideoObject : NSObject 1015 | /*! @brief 返回一个WXVideoObject对象 1016 | * 1017 | * @note 返回的WXVideoObject对象是自动释放的 1018 | */ 1019 | + (WXVideoObject *)object; 1020 | 1021 | /** 视频网页的url地址 1022 | * @note 长度不能超过10K 1023 | */ 1024 | @property (nonatomic, copy) NSString *videoUrl; 1025 | /** 视频lowband网页的url地址 1026 | * @note 长度不能超过10K 1027 | */ 1028 | @property (nonatomic, copy) NSString *videoLowBandUrl; 1029 | 1030 | @end 1031 | 1032 | 1033 | 1034 | #pragma mark - WXWebpageObject 1035 | /*! @brief 多媒体消息中包含的网页数据对象 1036 | * 1037 | * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 1038 | * @see WXMediaMessage 1039 | */ 1040 | @interface WXWebpageObject : NSObject 1041 | /*! @brief 返回一个WXWebpageObject对象 1042 | * 1043 | * @note 返回的WXWebpageObject对象是自动释放的 1044 | */ 1045 | + (WXWebpageObject *)object; 1046 | 1047 | /** 网页的url地址 1048 | * @note 不能为空且长度不能超过10K 1049 | */ 1050 | @property (nonatomic, copy) NSString *webpageUrl; 1051 | 1052 | /**是否是私密消息 1053 | */ 1054 | @property (nonatomic, assign) BOOL isSecretMessage; 1055 | 1056 | /** 业务所需的额外信息 */ 1057 | @property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; 1058 | 1059 | @end 1060 | 1061 | 1062 | 1063 | #pragma mark - WXAppExtendObject 1064 | /*! @brief 多媒体消息中包含的App扩展数据对象 1065 | * 1066 | * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, 1067 | * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 1068 | * @note url,extInfo和fileData不能同时为空 1069 | * @see WXMediaMessage 1070 | */ 1071 | @interface WXAppExtendObject : NSObject 1072 | /*! @brief 返回一个WXAppExtendObject对象 1073 | * 1074 | * @note 返回的WXAppExtendObject对象是自动释放的 1075 | */ 1076 | + (WXAppExtendObject *)object; 1077 | 1078 | /** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 1079 | * @note 长度不能超过10K 1080 | */ 1081 | @property (nonatomic, copy) NSString *url; 1082 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 1083 | * @note 长度不能超过2K 1084 | */ 1085 | @property (nonatomic, copy, nullable) NSString *extInfo; 1086 | /** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 1087 | * @note 大小不能超过10M 1088 | */ 1089 | @property (nonatomic, strong, nullable) NSData *fileData; 1090 | 1091 | @end 1092 | 1093 | 1094 | 1095 | #pragma mark - WXEmoticonObject 1096 | /*! @brief 多媒体消息中包含的表情数据对象 1097 | * 1098 | * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 1099 | * @see WXMediaMessage 1100 | */ 1101 | @interface WXEmoticonObject : NSObject 1102 | 1103 | /*! @brief 返回一个WXEmoticonObject对象 1104 | * 1105 | * @note 返回的WXEmoticonObject对象是自动释放的 1106 | */ 1107 | + (WXEmoticonObject *)object; 1108 | 1109 | /** 表情真实数据内容 1110 | * @note 大小不能超过10M 1111 | */ 1112 | @property (nonatomic, strong) NSData *emoticonData; 1113 | 1114 | @end 1115 | 1116 | 1117 | 1118 | #pragma mark - WXFileObject 1119 | /*! @brief 多媒体消息中包含的文件数据对象 1120 | * 1121 | * @see WXMediaMessage 1122 | */ 1123 | @interface WXFileObject : NSObject 1124 | 1125 | /*! @brief 返回一个WXFileObject对象 1126 | * 1127 | * @note 返回的WXFileObject对象是自动释放的 1128 | */ 1129 | + (WXFileObject *)object; 1130 | 1131 | /** 文件后缀名 1132 | * @note 长度不超过64字节 1133 | */ 1134 | @property (nonatomic, copy) NSString *fileExtension; 1135 | 1136 | /** 文件真实数据内容 1137 | * @note 大小不能超过10M 1138 | */ 1139 | @property (nonatomic, strong) NSData *fileData; 1140 | 1141 | @end 1142 | 1143 | 1144 | #pragma mark - WXLocationObject 1145 | /*! @brief 多媒体消息中包含的地理位置数据对象 1146 | * 1147 | * 微信终端和第三方程序之间传递消息中包含的地理位置数据对象。 1148 | * @see WXMediaMessage 1149 | */ 1150 | @interface WXLocationObject : NSObject 1151 | 1152 | /*! @brief 返回一个WXLocationObject对象 1153 | * 1154 | * @note 返回的WXLocationObject对象是自动释放的 1155 | */ 1156 | + (WXLocationObject *)object; 1157 | 1158 | /** 地理位置信息 1159 | * @note 经纬度 1160 | */ 1161 | @property (nonatomic, assign) double lng; //经度 1162 | @property (nonatomic, assign) double lat; //纬度 1163 | 1164 | @end 1165 | 1166 | #pragma mark - WXTextObject 1167 | /*! @brief 多媒体消息中包含的文本数据对象 1168 | * 1169 | * 微信终端和第三方程序之间传递消息中包含的文本数据对象。 1170 | * @see WXMediaMessage 1171 | */ 1172 | @interface WXTextObject : NSObject 1173 | 1174 | /*! @brief 返回一个WXTextObject对象 1175 | * 1176 | * @note 返回的WXTextObject对象是自动释放的 1177 | */ 1178 | + (WXTextObject *)object; 1179 | 1180 | /** 地理位置信息 1181 | * @note 文本内容 1182 | */ 1183 | @property (nonatomic, copy) NSString *contentText; 1184 | 1185 | @end 1186 | 1187 | #pragma mark - WXMiniProgramObject 1188 | 1189 | @interface WXMiniProgramObject : NSObject 1190 | 1191 | /*! @brief WXMiniProgramObject对象 1192 | * 1193 | * @note 返回的WXMiniProgramObject对象是自动释放的 1194 | */ 1195 | + (WXMiniProgramObject *)object; 1196 | 1197 | /** 低版本网页链接 1198 | * @attention 长度不能超过1024字节 1199 | */ 1200 | @property (nonatomic, copy) NSString *webpageUrl; 1201 | 1202 | /** 小程序username */ 1203 | @property (nonatomic, copy) NSString *userName; 1204 | 1205 | /** 小程序页面的路径 1206 | * @attention 不填默认拉起小程序首页 1207 | */ 1208 | @property (nonatomic, copy, nullable) NSString *path; 1209 | 1210 | /** 小程序新版本的预览图 1211 | * @attention 大小不能超过128k 1212 | */ 1213 | @property (nonatomic, strong, nullable) NSData *hdImageData; 1214 | 1215 | /** 是否使用带 shareTicket 的转发 */ 1216 | @property (nonatomic, assign) BOOL withShareTicket; 1217 | 1218 | /** 分享小程序的版本 1219 | * @attention (正式,开发,体验) 1220 | */ 1221 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; 1222 | 1223 | /** 是否禁用转发 */ 1224 | @property (nonatomic, assign) BOOL disableForward; 1225 | 1226 | @property (nonatomic, assign) BOOL isUpdatableMessage; 1227 | 1228 | @property (nonatomic, assign) BOOL isSecretMessage; 1229 | 1230 | 1231 | /** 业务所需的额外信息 */ 1232 | @property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; 1233 | 1234 | @end 1235 | 1236 | #pragma mark - WXGameLiveObject 1237 | 1238 | /*! @brief WXGameLiveObject对象 1239 | * 1240 | * @note 游戏直播消息类型 1241 | */ 1242 | 1243 | @interface WXGameLiveObject : NSObject 1244 | 1245 | + (WXGameLiveObject *)object; 1246 | 1247 | /** 业务所需的额外信息 */ 1248 | @property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; 1249 | 1250 | @end 1251 | 1252 | @interface WXNativeGamePageObject : NSObject 1253 | 1254 | /** 是否为视频类型 1255 | */ 1256 | @property (nonatomic, assign) BOOL isVideo; 1257 | 1258 | /** 视频时长 1259 | @note 当为视频类型时,必填;单位为秒 1260 | */ 1261 | @property (nonatomic, assign) UInt32 videoDuration; 1262 | 1263 | /** 透传字段 1264 | @note 长度限制为100K 1265 | */ 1266 | @property (nonatomic, copy) NSString *shareData; 1267 | 1268 | /** 缩略图 1269 | @note 大小限制为256K 1270 | */ 1271 | @property (nonatomic, strong) NSData *gameThumbData; 1272 | 1273 | + (WXNativeGamePageObject *)object; 1274 | 1275 | @end 1276 | 1277 | #pragma mark - WXLaunchMiniProgramReq 1278 | 1279 | /*! @brief WXLaunchMiniProgramReq对象, 可实现通过sdk拉起微信小程序 1280 | * 1281 | * @note 返回的WXLaunchMiniProgramReq对象是自动释放的 1282 | */ 1283 | @interface WXLaunchMiniProgramReq : BaseReq 1284 | 1285 | + (WXLaunchMiniProgramReq *)object; 1286 | 1287 | /** 小程序username */ 1288 | @property (nonatomic, copy) NSString *userName; 1289 | 1290 | /** 小程序页面的路径 1291 | * @attention 不填默认拉起小程序首页 1292 | */ 1293 | @property (nonatomic, copy, nullable) NSString *path; 1294 | 1295 | /** 分享小程序的版本 1296 | * @attention (正式,开发,体验) 1297 | */ 1298 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; 1299 | 1300 | /** ext信息 1301 | * @attention json格式 1302 | */ 1303 | @property (nonatomic, copy, nullable) NSString *extMsg; 1304 | 1305 | /** extDic 1306 | * @attention 字典,可存放图片等比较大的数据 1307 | */ 1308 | @property (nonatomic, copy, nullable) NSDictionary *extDic; 1309 | 1310 | @end 1311 | 1312 | #pragma mark - WXLaunchMiniProgramResp 1313 | /*! @brief 微信终端向第三方程序返回的WXLaunchMiniProgramReq处理结果。 1314 | * 1315 | * 第三方程序向微信终端发送WXLaunchMiniProgramReq后,微信发送回来的处理结果,该结果用WXLaunchMiniProgramResp表示。 1316 | */ 1317 | @interface WXLaunchMiniProgramResp : BaseResp 1318 | 1319 | @property (nonatomic, copy, nullable) NSString *extMsg; 1320 | 1321 | @end 1322 | 1323 | 1324 | #pragma mark - WXOpenBusinessViewReq 1325 | /*! @brief WXOpenBusinessViewReq对象, 可实现第三方通知微信启动,打开业务页面 1326 | * 1327 | * @note 返回的WXOpenBusinessViewReq对象是自动释放的 1328 | */ 1329 | 1330 | @interface WXOpenBusinessViewReq : BaseReq 1331 | 1332 | + (WXOpenBusinessViewReq *)object; 1333 | 1334 | /** 业务类型 1335 | */ 1336 | @property (nonatomic, copy) NSString *businessType; 1337 | 1338 | /** 业务参数 1339 | */ 1340 | @property (nonatomic, copy, nullable) NSString *query; 1341 | 1342 | /** ext信息 1343 | * @note 选填,json格式 1344 | */ 1345 | @property (nonatomic, copy, nullable) NSString *extInfo; 1346 | 1347 | /** extData数据 1348 | * @note 1349 | */ 1350 | @property (nonatomic, strong, nullable) NSData *extData; 1351 | @end 1352 | 1353 | 1354 | @interface WXOpenBusinessViewResp : BaseResp 1355 | 1356 | /** 业务类型 1357 | */ 1358 | @property (nonatomic, copy) NSString *businessType; 1359 | 1360 | /** 业务返回数据 1361 | */ 1362 | @property (nonatomic, copy, nullable) NSString *extMsg; 1363 | 1364 | @end 1365 | 1366 | #pragma mark - WXOpenCustomerServiceReq 1367 | @interface WXOpenCustomerServiceReq : BaseReq 1368 | 1369 | + (WXOpenCustomerServiceReq *)object; 1370 | 1371 | /**企微客服发起流程 url 1372 | */ 1373 | @property (nonatomic, copy, nullable) NSString *url; 1374 | 1375 | /**企业 id 1376 | */ 1377 | @property (nonatomic, copy, nullable) NSString *corpid; 1378 | 1379 | @end 1380 | 1381 | @interface WXOpenCustomerServiceResp : BaseResp 1382 | 1383 | /** 业务返回数据 1384 | */ 1385 | @property (nonatomic, copy, nullable) NSString *extMsg; 1386 | 1387 | @end 1388 | 1389 | 1390 | #pragma mark - WXChannelStartLiveReq 1391 | 1392 | @interface WXChannelStartLiveReq : BaseReq 1393 | 1394 | + (WXChannelStartLiveReq *)object; 1395 | 1396 | /** 必填,直播业务数据(json格式) 1397 | */ 1398 | @property (nonatomic, copy) NSString *liveJsonInfo; 1399 | 1400 | @end 1401 | 1402 | @interface WXChannelStartLiveResp : BaseResp 1403 | 1404 | /** 业务返回数据 1405 | */ 1406 | @property (nonatomic, copy, nullable) NSString *extMsg; 1407 | 1408 | @end 1409 | 1410 | NS_ASSUME_NONNULL_END 1411 | -------------------------------------------------------------------------------- /ios/WechatOpenSDK-XCFramework.xcframework/ios-arm64_i386_x86_64-simulator/Headers/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 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /*! @brief 错误码 15 | * 16 | */ 17 | enum WXErrCode { 18 | WXSuccess = 0, /**< 成功 */ 19 | WXErrCodeCommon = -1, /**< 普通错误类型 */ 20 | WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ 21 | WXErrCodeSentFail = -3, /**< 发送失败 */ 22 | WXErrCodeAuthDeny = -4, /**< 授权失败 */ 23 | WXErrCodeUnsupport = -5, /**< 微信不支持 */ 24 | }; 25 | 26 | 27 | 28 | /*! @brief 请求发送场景 29 | * 30 | */ 31 | enum WXScene { 32 | WXSceneSession = 0, /**< 聊天界面 */ 33 | WXSceneTimeline = 1, /**< 朋友圈 */ 34 | WXSceneFavorite = 2, /**< 收藏 */ 35 | WXSceneSpecifiedSession = 3, /**< 指定联系人 */ 36 | WXSceneState = 4, /**< 状态 */ 37 | }; 38 | 39 | 40 | enum WXAPISupport { 41 | WXAPISupportSession = 0, 42 | }; 43 | 44 | 45 | 46 | /*! @brief 跳转profile类型 47 | * 48 | */ 49 | enum WXBizProfileType { 50 | WXBizProfileType_Normal = 0, //**< 普通公众号 */ 51 | WXBizProfileType_Device = 1, //**< 硬件公众号 */ 52 | }; 53 | 54 | /*! @brief 分享小程序类型 55 | * 56 | */ 57 | typedef NS_ENUM(NSUInteger, WXMiniProgramType) { 58 | WXMiniProgramTypeRelease = 0, //**< 正式版 */ 59 | WXMiniProgramTypeTest = 1, //**< 开发版 */ 60 | WXMiniProgramTypePreview = 2, //**< 体验版 */ 61 | }; 62 | 63 | /*! @brief 跳转mp网页类型 64 | * 65 | */ 66 | enum WXMPWebviewType { 67 | WXMPWebviewType_Ad = 0, /**< 广告网页 **/ 68 | }; 69 | 70 | /*! @brief log的级别 71 | * 72 | */ 73 | typedef NS_ENUM(NSInteger,WXLogLevel) { 74 | WXLogLevelNormal = 0, // 打印日常的日志 75 | WXLogLevelDetail = 1, // 打印详细的日志 76 | }; 77 | 78 | 79 | /*! @brief 打印回调的block 80 | * 81 | */ 82 | typedef void(^WXLogBolock)(NSString *log); 83 | 84 | /*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),检查步骤枚举值 85 | * 86 | * WXULCheckStepParams 参数检测 87 | * WXULCheckStepSystemVersion 当前系统版本检测 88 | * WXULCheckStepWechatVersion 微信客户端版本检测 89 | * WXULCheckStepSDKInnerOperation 微信SDK内部操作检测 90 | * WXULCheckStepLaunchWechat App拉起微信检测 91 | * WXULCheckStepBackToCurrentApp 由微信返回当前App检测 92 | * WXULCheckStepFinal 最终结果 93 | */ 94 | typedef NS_ENUM(NSInteger, WXULCheckStep) 95 | { 96 | WXULCheckStepParams, 97 | WXULCheckStepSystemVersion, 98 | WXULCheckStepWechatVersion, 99 | WXULCheckStepSDKInnerOperation, 100 | WXULCheckStepLaunchWechat, 101 | WXULCheckStepBackToCurrentApp, 102 | WXULCheckStepFinal, 103 | }; 104 | 105 | 106 | #pragma mark - WXCheckULStepResult 107 | 108 | /*! @brief 该类为微信Universal Link检测函数结果类 109 | * 110 | */ 111 | @interface WXCheckULStepResult : NSObject 112 | 113 | /** 是否成功 */ 114 | @property(nonatomic, assign) BOOL success; 115 | /** 当前错误信息 */ 116 | @property(nonatomic, strong) NSString* errorInfo; 117 | /** 修正建议 */ 118 | @property(nonatomic, strong) NSString* suggestion; 119 | 120 | - (instancetype)initWithCheckResult:(BOOL)success errorInfo:(nullable NSString*)errorInfo suggestion:(nullable NSString*)suggestion; 121 | 122 | @end 123 | 124 | 125 | /*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),回调Block 126 | * 127 | * @param step 当前检测步骤 128 | * @param result 检测结果 129 | */ 130 | typedef void(^WXCheckULCompletion)(WXULCheckStep step, WXCheckULStepResult* result); 131 | 132 | 133 | #pragma mark - BaseReq 134 | /*! @brief 该类为微信终端SDK所有请求类的基类 135 | * 136 | */ 137 | @interface BaseReq : NSObject 138 | 139 | /** 请求类型 */ 140 | @property (nonatomic, assign) int type; 141 | /** 由用户微信号和AppID组成的唯一标识,需要校验微信用户是否换号登录时填写*/ 142 | @property (nonatomic, copy) NSString *openID; 143 | 144 | @end 145 | 146 | 147 | 148 | #pragma mark - BaseResp 149 | /*! @brief 该类为微信终端SDK所有响应类的基类 150 | * 151 | */ 152 | @interface BaseResp : NSObject 153 | /** 错误码 */ 154 | @property (nonatomic, assign) int errCode; 155 | /** 错误提示字符串 */ 156 | @property (nonatomic, copy) NSString *errStr; 157 | /** 响应类型 */ 158 | @property (nonatomic, assign) int type; 159 | 160 | @end 161 | 162 | 163 | 164 | #pragma mark - WXMediaMessage 165 | @class WXMediaMessage; 166 | 167 | #ifndef BUILD_WITHOUT_PAY 168 | 169 | #pragma mark - PayReq 170 | /*! @brief 第三方向微信终端发起支付的消息结构体 171 | * 172 | * 第三方向微信终端发起支付的消息结构体,微信终端处理后会向第三方返回处理结果 173 | * @see PayResp 174 | */ 175 | @interface PayReq : BaseReq 176 | 177 | /** 商家向财付通申请的商家id */ 178 | @property (nonatomic, copy) NSString *partnerId; 179 | /** 预支付订单 */ 180 | @property (nonatomic, copy) NSString *prepayId; 181 | /** 随机串,防重发 */ 182 | @property (nonatomic, copy) NSString *nonceStr; 183 | /** 时间戳,防重发 */ 184 | @property (nonatomic, assign) UInt32 timeStamp; 185 | /** 商家根据财付通文档填写的数据和签名 */ 186 | @property (nonatomic, copy) NSString *package; 187 | /** 商家根据微信开放平台文档对数据做的签名 */ 188 | @property (nonatomic, copy) NSString *sign; 189 | 190 | @end 191 | 192 | 193 | #pragma mark - PayResp 194 | /*! @brief 微信终端返回给第三方的关于支付结果的结构体 195 | * 196 | * 微信终端返回给第三方的关于支付结果的结构体 197 | */ 198 | @interface PayResp : BaseResp 199 | 200 | /** 财付通返回给商家的信息 */ 201 | @property (nonatomic, copy) NSString *returnKey; 202 | 203 | @end 204 | 205 | #pragma mark - WXOfflinePay 206 | /*! @brief 第三方向微信终端发起离线支付 207 | * 208 | * 第三方向微信终端发起离线支付的消息结构体 209 | */ 210 | @interface WXOfflinePayReq : BaseReq 211 | 212 | @end 213 | 214 | /*! @brief 第三方向微信终端发起离线支付返回 215 | * 216 | * 第三方向微信终端发起离线支付返回的消息结构体 217 | */ 218 | @interface WXOfflinePayResp : BaseResp 219 | 220 | @end 221 | 222 | 223 | #pragma mark - WXNontaxPayReq 224 | @interface WXNontaxPayReq:BaseReq 225 | 226 | @property (nonatomic, copy) NSString *urlString; 227 | 228 | @end 229 | 230 | #pragma mark - WXNontaxPayResp 231 | @interface WXNontaxPayResp : BaseResp 232 | 233 | @property (nonatomic, copy) NSString *wxOrderId; 234 | 235 | @end 236 | 237 | #pragma mark - WXPayInsuranceReq 238 | @interface WXPayInsuranceReq : BaseReq 239 | 240 | @property (nonatomic, copy) NSString *urlString; 241 | 242 | @end 243 | 244 | #pragma mark - WXPayInsuranceResp 245 | @interface WXPayInsuranceResp : BaseResp 246 | 247 | @property (nonatomic, copy) NSString *wxOrderId; 248 | 249 | @end 250 | 251 | 252 | #pragma mark - WXQRCodePayReq 253 | @interface WXQRCodePayReq : BaseReq 254 | /** 码内容 255 | * @note 必填,码长度必须大于0且小于10K 256 | */ 257 | @property (nonatomic, copy) NSString *codeContent; 258 | /** 额外信息 259 | * @note 长度必须大于0且小于10K 260 | */ 261 | @property (nonatomic, copy) NSString *extraMsg; 262 | 263 | @end 264 | 265 | @interface WXQRCodePayResp : BaseResp 266 | @end 267 | 268 | #endif 269 | 270 | 271 | #pragma mark - SendAuthReq 272 | /*! @brief 第三方程序向微信终端请求认证的消息结构 273 | * 274 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, 275 | * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 276 | * @see SendAuthResp 277 | */ 278 | @interface SendAuthReq : BaseReq 279 | /** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 280 | * @see SendAuthResp 281 | * @note scope字符串长度不能超过1K 282 | */ 283 | @property (nonatomic, copy) NSString *scope; 284 | /** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 285 | * @note state字符串长度不能超过1K 286 | */ 287 | @property (nonatomic, copy) NSString *state; 288 | 289 | @property (nonatomic, assign) BOOL isOption1; 290 | 291 | /** 是否关闭自动授权 292 | * @note YES为关闭自动授权,每次登陆都需要用户手动授权;NO为允许自动授权 293 | */ 294 | @property (nonatomic, assign) BOOL nonautomatic; 295 | 296 | @property (nonatomic, copy) NSString *extData; 297 | 298 | @end 299 | 300 | #pragma mark - SendAuthResp 301 | /*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 302 | * 303 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 304 | * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 305 | * @see onResp 306 | */ 307 | @interface SendAuthResp : BaseResp 308 | @property (nonatomic, copy, nullable) NSString *code; 309 | /** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 310 | * @note state字符串长度不能超过1K 311 | * @note 在复杂度较高的应用程序中,可能会出现其他模块请求的响应对象被错误地回调到当前模块。 312 | * 为了避免影响其他模块,建议当前模块的开发者根据SendAuthResp的内容,采用白名单的方式进行处理。 313 | * 例如,SendAuthResp.state符合预期时,才对其进行处理。 314 | */ 315 | @property (nonatomic, copy, nullable) NSString *state; 316 | @property (nonatomic, copy, nullable) NSString *lang; 317 | @property (nonatomic, copy, nullable) NSString *country; 318 | @end 319 | 320 | #pragma mark - WXStateJumpInfo 321 | /*! @brief 状态发表时的小尾巴跳转信息 322 | */ 323 | @interface WXStateJumpInfo : NSObject 324 | 325 | @end 326 | 327 | #pragma mark - WXStateJumpUrlInfo 328 | /*! @brief 状态小尾巴跳转指定url的信息 329 | */ 330 | @interface WXStateJumpUrlInfo : WXStateJumpInfo 331 | /** 跳转到指定的url 332 | * @note 必填,url长度必须大于0且小于10K 333 | */ 334 | @property (nonatomic, copy) NSString *url; 335 | 336 | @end 337 | 338 | #pragma mark - WXStateJumpWXMiniProgramInfo 339 | /*! @brief 状态小尾巴跳转指定小程序的信息 340 | */ 341 | @interface WXStateJumpMiniProgramInfo : WXStateJumpInfo 342 | /** 小程序username 343 | * @note 必填 344 | */ 345 | @property (nonatomic, copy) NSString *username; 346 | 347 | /** 小程序页面的路径 348 | * @attention 不填默认拉起小程序首页 349 | */ 350 | @property (nonatomic, copy, nullable) NSString *path; 351 | 352 | /** 分享小程序的版本 353 | * @attention (正式,开发,体验) 354 | */ 355 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; 356 | 357 | @end 358 | 359 | 360 | 361 | #pragma mark - WXStateJumpWXMiniProgramInfo 362 | /*! @brief 状态小尾巴跳转指定视频号主页信息 363 | */ 364 | @interface WXStateJumpChannelProfileInfo : WXStateJumpInfo 365 | /** 视频号username 366 | * @note 必填,username长度必须大于0且小于1K 367 | */ 368 | @property (nonatomic, copy) NSString *username; 369 | 370 | 371 | @end 372 | 373 | #pragma mark - WXStateSceneDataObject 374 | /*! @brief 场景类型额外参数基类 375 | */ 376 | @interface WXSceneDataObject : NSObject 377 | 378 | @end 379 | 380 | #pragma mark - WXStateSceneDataObject 381 | /*! @brief 状态场景类型 382 | * 用户填写WXStateSceneDataObject参数后,可以跳转到微信状态发表页 383 | */ 384 | @interface WXStateSceneDataObject : WXSceneDataObject 385 | 386 | /** 状态标志的ID 387 | * @note 选填,文本长度必须小于10K 388 | */ 389 | @property (nonatomic, copy) NSString *stateId; 390 | /** 状态发表时附带的文本描述 391 | * @note 选填,文本长度必须小于10K 392 | */ 393 | @property (nonatomic, copy) NSString *stateTitle; 394 | /** 后台校验token 395 | * @note 选填,文本长度必须小于10K 396 | */ 397 | @property (nonatomic, copy) NSString *token; 398 | /** 小尾巴跳转所需的信息 399 | * @note 必填,目前仅支持url跳转 400 | */ 401 | @property (nonatomic, strong) WXStateJumpInfo *stateJumpDataInfo; 402 | 403 | @end 404 | 405 | #pragma mark - SendMessageToWXReq 406 | /*! @brief 第三方程序发送消息至微信终端程序的消息结构体 407 | * 408 | * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, 409 | * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 410 | * @see SendMessageToWXResp 411 | */ 412 | @interface SendMessageToWXReq : BaseReq 413 | /** 发送消息的文本内容 414 | * @note 文本长度必须大于0且小于10K 415 | */ 416 | @property (nonatomic, copy) NSString *text; 417 | /** 发送消息的多媒体内容 418 | * @see WXMediaMessage 419 | */ 420 | @property (nonatomic, strong) WXMediaMessage *message; 421 | /** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 422 | @property (nonatomic, assign) BOOL bText; 423 | /** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 424 | * @see WXScene 425 | */ 426 | @property (nonatomic, assign) int scene; 427 | /** 指定发送消息的人 428 | * @note WXSceneSpecifiedSession时有效 429 | */ 430 | @property (nonatomic, copy, nullable) NSString *toUserOpenId; 431 | /** 目标场景附带信息 432 | * @note 目前只针对状态场景 433 | */ 434 | @property (nonatomic, strong) WXSceneDataObject *sceneDataObject; 435 | 436 | @end 437 | 438 | #pragma mark - SendMessageToWXResp 439 | /*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 440 | * 441 | * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 442 | */ 443 | @interface SendMessageToWXResp : BaseResp 444 | @property(nonatomic, copy) NSString *lang; 445 | @property(nonatomic, copy) NSString *country; 446 | @end 447 | 448 | #pragma mark - GetMessageFromWXReq 449 | /*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 450 | * 451 | * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, 452 | * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 453 | */ 454 | @interface GetMessageFromWXReq : BaseReq 455 | @property (nonatomic, strong) NSString *lang; 456 | @property (nonatomic, strong) NSString *country; 457 | @end 458 | 459 | 460 | 461 | #pragma mark - GetMessageFromWXResp 462 | /*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 463 | * 464 | * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 465 | */ 466 | @interface GetMessageFromWXResp : BaseResp 467 | /** 向微信终端提供的文本内容 468 | @note 文本长度必须大于0且小于10K 469 | */ 470 | @property (nonatomic, strong) NSString *text; 471 | /** 向微信终端提供的多媒体内容。 472 | * @see WXMediaMessage 473 | */ 474 | @property (nonatomic, strong) WXMediaMessage *message; 475 | /** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 476 | @property (nonatomic, assign) BOOL bText; 477 | @end 478 | 479 | 480 | 481 | #pragma mark - ShowMessageFromWXReq 482 | /*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 483 | * 484 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 485 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 486 | */ 487 | @interface ShowMessageFromWXReq : BaseReq 488 | /** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 489 | * @see WXMediaMessage 490 | */ 491 | @property (nonatomic, strong) WXMediaMessage *message; 492 | @property (nonatomic, copy) NSString *lang; 493 | @property (nonatomic, copy) NSString *country; 494 | @end 495 | 496 | 497 | 498 | #pragma mark - ShowMessageFromWXResp 499 | /*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 500 | * 501 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 502 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 503 | */ 504 | @interface ShowMessageFromWXResp : BaseResp 505 | @end 506 | 507 | 508 | #pragma mark - LaunchFromWXReq 509 | /*! @brief 微信终端打开第三方程序携带的消息结构体 510 | * 511 | * 微信向第三方发送的结构体,第三方不需要返回 512 | */ 513 | @interface LaunchFromWXReq : BaseReq 514 | @property (nonatomic, strong) WXMediaMessage *message; 515 | @property (nonatomic, copy) NSString *lang; 516 | @property (nonatomic, copy) NSString *country; 517 | @end 518 | 519 | 520 | #pragma mark - OpenWebviewReq 521 | /* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 522 | * 523 | * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 524 | */ 525 | @interface OpenWebviewReq : BaseReq 526 | /** 需要打开的网页对应的Url 527 | * @attention 长度不能超过1024 528 | */ 529 | @property(nonatomic, copy) NSString *url; 530 | 531 | @end 532 | 533 | #pragma mark - OpenWebviewResp 534 | /*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 535 | * 536 | * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 537 | */ 538 | @interface OpenWebviewResp : BaseResp 539 | 540 | @end 541 | 542 | 543 | 544 | #pragma mark - WXOpenBusinessWebViewReq 545 | /*! @brief 第三方通知微信启动内部浏览器,打开指定业务的网页 546 | * 547 | * 548 | */ 549 | @interface WXOpenBusinessWebViewReq : BaseReq 550 | 551 | /** 网页业务类型 552 | * @attention 553 | */ 554 | @property (nonatomic, assign) UInt32 businessType; 555 | 556 | /** 网页业务参数 557 | * @attention 558 | */ 559 | @property (nonatomic, strong, nullable) NSDictionary *queryInfoDic; 560 | 561 | @end 562 | 563 | #pragma mark - WXOpenBusinessWebViewResp 564 | /*! @brief 微信终端向第三方程序返回的WXOpenBusinessWebViewResp处理结果。 565 | * 566 | * 第三方程序向微信终端发送WXOpenBusinessWebViewReq后,微信发送回来的处理结果,该结果用WXOpenBusinessWebViewResp表示。 567 | */ 568 | @interface WXOpenBusinessWebViewResp : BaseResp 569 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 570 | * @attention 长度不能超过2k 571 | */ 572 | @property (nonatomic, copy) NSString *result; 573 | 574 | /** 网页业务类型 575 | * @attention 576 | */ 577 | @property (nonatomic, assign) UInt32 businessType; 578 | 579 | @end 580 | 581 | 582 | #pragma mark - OpenRankListReq 583 | /* ! @brief 第三方通知微信,打开硬件排行榜 584 | * 585 | * 第三方通知微信,打开硬件排行榜 586 | */ 587 | @interface OpenRankListReq : BaseReq 588 | 589 | @end 590 | 591 | #pragma mark - OpenRanklistResp 592 | /*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 593 | * 594 | * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 595 | */ 596 | @interface OpenRankListResp : BaseResp 597 | 598 | @end 599 | 600 | 601 | #pragma mark - WXCardItem 602 | 603 | @interface WXCardItem : NSObject 604 | /** 卡id 605 | * @attention 长度不能超过1024字节 606 | */ 607 | @property (nonatomic, copy) NSString *cardId; 608 | /** ext信息 609 | * @attention 长度不能超过2024字节 610 | */ 611 | @property (nonatomic, copy, nullable) NSString *extMsg; 612 | /** 613 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 614 | */ 615 | @property (nonatomic, assign) UInt32 cardState; 616 | /** 617 | * @attention req不需要填,chooseCard返回的。 618 | */ 619 | @property (nonatomic, copy) NSString *encryptCode; 620 | /** 621 | * @attention req不需要填,chooseCard返回的。 622 | */ 623 | @property (nonatomic, copy) NSString *appID; 624 | @end; 625 | 626 | #pragma mark - WXInvoiceItem 627 | 628 | @interface WXInvoiceItem : NSObject 629 | /** 卡id 630 | * @attention 长度不能超过1024字节 631 | */ 632 | @property (nonatomic, copy) NSString *cardId; 633 | /** ext信息 634 | * @attention 长度不能超过2024字节 635 | */ 636 | @property (nonatomic, copy, nullable) NSString *extMsg; 637 | /** 638 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 639 | */ 640 | @property (nonatomic, assign) UInt32 cardState; 641 | /** 642 | * @attention req不需要填,chooseCard返回的。 643 | */ 644 | @property (nonatomic, copy) NSString *encryptCode; 645 | /** 646 | * @attention req不需要填,chooseCard返回的。 647 | */ 648 | @property (nonatomic, copy) NSString *appID; 649 | 650 | @end 651 | 652 | #pragma mark - AddCardToWXCardPackageReq 653 | /* ! @brief 请求添加卡券至微信卡包 654 | * 655 | */ 656 | 657 | @interface AddCardToWXCardPackageReq : BaseReq 658 | /** 卡列表 659 | * @attention 个数不能超过40个 类型WXCardItem 660 | */ 661 | @property (nonatomic, strong) NSArray *cardAry; 662 | 663 | @end 664 | 665 | 666 | #pragma mark - AddCardToWXCardPackageResp 667 | /** ! @brief 微信返回第三方添加卡券结果 668 | * 669 | */ 670 | 671 | @interface AddCardToWXCardPackageResp : BaseResp 672 | /** 卡列表 673 | * @attention 个数不能超过40个 类型WXCardItem 674 | */ 675 | @property (nonatomic, strong) NSArray *cardAry; 676 | @end 677 | 678 | #pragma mark - WXChooseCardReq 679 | /* ! @brief 请求从微信选取卡券 680 | * 681 | */ 682 | 683 | @interface WXChooseCardReq : BaseReq 684 | @property (nonatomic, copy) NSString *appID; 685 | @property (nonatomic, assign) UInt32 shopID; 686 | @property (nonatomic, assign) UInt32 canMultiSelect; 687 | @property (nonatomic, copy) NSString *cardType; 688 | @property (nonatomic, copy) NSString *cardTpID; 689 | @property (nonatomic, copy) NSString *signType; 690 | @property (nonatomic, copy) NSString *cardSign; 691 | @property (nonatomic, assign) UInt32 timeStamp; 692 | @property (nonatomic, copy) NSString *nonceStr; 693 | @end 694 | 695 | 696 | #pragma mark - WXChooseCardResp 697 | /** ! @brief 微信返回第三方请求选择卡券结果 698 | * 699 | */ 700 | 701 | @interface WXChooseCardResp : BaseResp 702 | @property (nonatomic, strong ) NSArray* cardAry; 703 | @end 704 | 705 | 706 | #pragma mark - WXChooseInvoiceReq 707 | /* ! @brief 请求从微信选取发票 708 | * 709 | */ 710 | @interface WXChooseInvoiceReq : BaseReq 711 | @property (nonatomic, copy) NSString *appID; 712 | @property (nonatomic, assign) UInt32 shopID; 713 | @property (nonatomic, copy) NSString *signType; 714 | @property (nonatomic, copy) NSString *cardSign; 715 | @property (nonatomic, assign) UInt32 timeStamp; 716 | @property (nonatomic, copy) NSString *nonceStr; 717 | @end 718 | 719 | #pragma mark - WXChooseInvoiceResp 720 | /** ! @brief 微信返回第三方请求选择发票结果 721 | * 722 | */ 723 | @interface WXChooseInvoiceResp : BaseResp 724 | @property (nonatomic, strong) NSArray* cardAry; 725 | @end 726 | 727 | #pragma mark - WXSubscriptionReq 728 | @interface WXSubscribeMsgReq : BaseReq 729 | @property (nonatomic, assign) UInt32 scene; 730 | @property (nonatomic, copy) NSString *templateId; 731 | @property (nonatomic, copy, nullable) NSString *reserved; 732 | @end 733 | 734 | #pragma mark - WXSubscriptionReq 735 | @interface WXSubscribeMsgResp : BaseResp 736 | 737 | @property (nonatomic, copy) NSString *templateId; 738 | @property (nonatomic, assign) UInt32 scene; 739 | @property (nonatomic, copy) NSString *action; 740 | @property (nonatomic, copy) NSString *reserved; 741 | @property (nonatomic, copy, nullable) NSString *openId; 742 | 743 | @end 744 | 745 | #pragma mark - WXSubscribeMiniProgramMsg 746 | /** ! @brief 第三方请求订阅小程序消息 747 | * 748 | */ 749 | @interface WXSubscribeMiniProgramMsgReq : BaseReq 750 | @property (nonatomic, copy) NSString *miniProgramAppid; 751 | @end 752 | 753 | #pragma mark - WXSubscriptionReq 754 | @interface WXSubscribeMiniProgramMsgResp : BaseResp 755 | 756 | @property(nonatomic, copy) NSString *openId; // 小程序openid 757 | @property(nonatomic, copy) NSString *unionId; // unionId 758 | @property(nonatomic, copy) NSString *nickName; // 用户昵称 759 | 760 | @end 761 | 762 | #pragma mark - WXinvoiceAuthInsertReq 763 | @interface WXInvoiceAuthInsertReq : BaseReq 764 | 765 | @property (nonatomic, copy) NSString *urlString; 766 | 767 | @end 768 | 769 | #pragma mark - WXinvoiceAuthInsertResp 770 | 771 | @interface WXInvoiceAuthInsertResp : BaseResp 772 | 773 | @property (nonatomic, copy) NSString *wxOrderId; 774 | 775 | @end 776 | 777 | #pragma mark - WXMediaMessage 778 | 779 | /*! @brief 多媒体消息结构体 780 | * 781 | * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 782 | */ 783 | @interface WXMediaMessage : NSObject 784 | 785 | + (WXMediaMessage *)message; 786 | 787 | /** 标题 788 | * @note 长度不能超过512字节 789 | */ 790 | @property (nonatomic, copy) NSString *title; 791 | /** 描述内容 792 | * @note 长度不能超过1K 793 | */ 794 | @property (nonatomic, copy) NSString *description; 795 | /** 缩略图数据 796 | * @note 大小不能超过64K 797 | */ 798 | @property (nonatomic, strong, nullable) NSData *thumbData; 799 | /** 800 | * @note 长度不能超过64字节 801 | */ 802 | @property (nonatomic, copy, nullable) NSString *mediaTagName; 803 | /** 804 | * 805 | */ 806 | @property (nonatomic, copy, nullable) NSString *messageExt; 807 | @property (nonatomic, copy, nullable) NSString *messageAction; 808 | /** 809 | * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 810 | */ 811 | @property (nonatomic, strong) id mediaObject; 812 | 813 | /** 缩略图的hash值 814 | * @note 使用sha256得到,用于计算签名 815 | */ 816 | @property (nonatomic, copy, nullable) NSString *thumbDataHash; 817 | 818 | /** 消息签名 819 | * @note 用于校验消息体是否被篡改过 820 | */ 821 | @property (nonatomic, copy, nullable) NSString *msgSignature; 822 | 823 | 824 | /*! @brief 设置消息缩略图的方法 825 | * 826 | * @param image 缩略图 827 | * @note 大小不能超过256K 828 | */ 829 | - (void)setThumbImage:(UIImage *)image; 830 | 831 | @end 832 | 833 | 834 | 835 | #pragma mark - WXImageObject 836 | /*! @brief 多媒体消息中包含的图片数据对象 837 | * 838 | * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 839 | * @note imageData成员不能为空 840 | * @see WXMediaMessage 841 | */ 842 | @interface WXImageObject : NSObject 843 | /*! @brief 返回一个WXImageObject对象 844 | * 845 | * @note 返回的WXImageObject对象是自动释放的 846 | */ 847 | + (WXImageObject *)object; 848 | 849 | /** 图片真实数据内容 850 | * @note 大小不能超过25M 851 | */ 852 | @property (nonatomic, strong) NSData *imageData; 853 | 854 | /** 图片数据的hash值 855 | * @note 使用sha256得到,用于计算签名 856 | */ 857 | @property (nonatomic, copy, nullable) NSString *imgDataHash; 858 | 859 | /** 分享的图片消息是否要带小程序入口,若 'entranceMiniProgramUsername' 非空则显示 860 | * 仅部分小程序类目可用 861 | * @note 本字段为空则发送普通app图片消息 862 | */ 863 | @property (nonatomic, copy, nullable) NSString *entranceMiniProgramUsername; 864 | 865 | /** 分享的图片消息显示的小程序入口可以跳转的小程序路径 866 | * 仅当 'entranceMiniProgramUsername' 非空时生效 867 | */ 868 | @property (nonatomic, copy, nullable) NSString *entranceMiniProgramPath; 869 | 870 | @end 871 | 872 | 873 | #pragma mark - WXMusicObject 874 | /*! @brief 多媒体消息中包含的音乐数据对象 875 | * 876 | * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 877 | * @note musicUrl和musicLowBandUrl成员不能同时为空。 878 | * @see WXMediaMessage 879 | */ 880 | @interface WXMusicObject : NSObject 881 | /*! @brief 返回一个WXMusicObject对象 882 | * 883 | * @note 返回的WXMusicObject对象是自动释放的 884 | */ 885 | + (WXMusicObject *)object; 886 | 887 | /** 音乐网页的url地址 888 | * @note 长度不能超过10K 889 | */ 890 | @property (nonatomic, copy) NSString *musicUrl; 891 | /** 音乐lowband网页的url地址 892 | * @note 长度不能超过10K 893 | */ 894 | @property (nonatomic, copy) NSString *musicLowBandUrl; 895 | /** 音乐数据url地址 896 | * @note 长度不能超过10K 897 | */ 898 | @property (nonatomic, copy) NSString *musicDataUrl; 899 | 900 | /**音乐lowband数据url地址 901 | * @note 长度不能超过10K 902 | */ 903 | @property (nonatomic, copy) NSString *musicLowBandDataUrl; 904 | 905 | /**音乐封面图Url 906 | * @note 长度不能超过10K 907 | */ 908 | @property (nonatomic, copy) NSString *songAlbumUrl; 909 | 910 | /**歌词信息 LRC格式 911 | * @note 长度不能超过32K 912 | */ 913 | @property (nonatomic, copy, nullable) NSString *songLyric; 914 | @end 915 | 916 | 917 | 918 | #pragma mark - WXMusicVideoObject 919 | 920 | @interface WXMusicVipInfo : NSObject 921 | 922 | /**付费歌曲的id 923 | * @note 长度不能超过32K 924 | */ 925 | @property (nonatomic, copy) NSString *musicId; 926 | 927 | @end 928 | 929 | 930 | @interface WXMusicVideoObject : NSObject 931 | 932 | /*! @brief 返回一个WXMusicVideoObject对象 933 | * 934 | * @note 返回的WXMusicVideoObject对象是自动释放的 935 | */ 936 | + (WXMusicVideoObject *)object; 937 | 938 | /** 音乐网页的url地址 939 | * @note 长度不能超过10K,不能为空 940 | */ 941 | @property (nonatomic, copy) NSString *musicUrl; 942 | 943 | /** 音乐数据url地址 944 | * @note 长度不能超过10K,不能为空 945 | */ 946 | @property (nonatomic, copy) NSString *musicDataUrl; 947 | 948 | /**歌手名 949 | * @note 长度不能超过1k,不能为空 950 | */ 951 | @property (nonatomic, copy) NSString *singerName; 952 | 953 | /** 954 | * @note 音乐时长, 单位毫秒 955 | */ 956 | @property (nonatomic, assign) UInt32 duration; 957 | 958 | /**歌词信息 LRC格式 959 | * @note 长度不能超过32K 960 | */ 961 | @property (nonatomic, copy) NSString *songLyric; 962 | 963 | /**高清封面图 964 | * @note 大小不能超过1M 965 | */ 966 | @property (nonatomic, strong) NSData *hdAlbumThumbData; 967 | 968 | /** 高清封面图数据的hash值 969 | * @note 使用sha256得到,用于计算签名 970 | */ 971 | @property (nonatomic, copy, nullable) NSString *hdAlbumThumbFileHash; 972 | 973 | /**音乐专辑名称 974 | * @note 长度不能超过1k 975 | */ 976 | @property (nonatomic, copy, nullable) NSString *albumName; 977 | 978 | /**音乐流派 979 | * @note 长度不能超过1k 980 | */ 981 | @property (nonatomic, copy, nullable) NSString *musicGenre; 982 | 983 | /**发行时间 984 | * @note Unix时间戳,单位为秒 985 | */ 986 | @property (nonatomic, assign) UInt64 issueDate; 987 | 988 | /**音乐标识符 989 | * @note 长度不能超过1K,从微信跳回应用时会带上 990 | */ 991 | @property (nonatomic, copy, nullable) NSString *identification; 992 | 993 | /**运营H5地址 994 | * @note 选填,建议填写,用户进入歌曲详情页将展示内嵌的运营H5,可展示该歌曲的相关评论、歌曲推荐等内容,不可诱导下载、分享等。 995 | */ 996 | @property (nonatomic, copy, nullable) NSString *musicOperationUrl; 997 | 998 | /** 付费歌曲相关信息 999 | * @note 选填,如果歌曲是需要付费的,那么将付费歌曲id等信息封装在内。 1000 | */ 1001 | @property (nonatomic, strong) WXMusicVipInfo *musicVipInfo; 1002 | 1003 | @end 1004 | 1005 | 1006 | 1007 | #pragma mark - WXVideoObject 1008 | /*! @brief 多媒体消息中包含的视频数据对象 1009 | * 1010 | * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 1011 | * @note videoUrl和videoLowBandUrl不能同时为空。 1012 | * @see WXMediaMessage 1013 | */ 1014 | @interface WXVideoObject : NSObject 1015 | /*! @brief 返回一个WXVideoObject对象 1016 | * 1017 | * @note 返回的WXVideoObject对象是自动释放的 1018 | */ 1019 | + (WXVideoObject *)object; 1020 | 1021 | /** 视频网页的url地址 1022 | * @note 长度不能超过10K 1023 | */ 1024 | @property (nonatomic, copy) NSString *videoUrl; 1025 | /** 视频lowband网页的url地址 1026 | * @note 长度不能超过10K 1027 | */ 1028 | @property (nonatomic, copy) NSString *videoLowBandUrl; 1029 | 1030 | @end 1031 | 1032 | 1033 | 1034 | #pragma mark - WXWebpageObject 1035 | /*! @brief 多媒体消息中包含的网页数据对象 1036 | * 1037 | * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 1038 | * @see WXMediaMessage 1039 | */ 1040 | @interface WXWebpageObject : NSObject 1041 | /*! @brief 返回一个WXWebpageObject对象 1042 | * 1043 | * @note 返回的WXWebpageObject对象是自动释放的 1044 | */ 1045 | + (WXWebpageObject *)object; 1046 | 1047 | /** 网页的url地址 1048 | * @note 不能为空且长度不能超过10K 1049 | */ 1050 | @property (nonatomic, copy) NSString *webpageUrl; 1051 | 1052 | /**是否是私密消息 1053 | */ 1054 | @property (nonatomic, assign) BOOL isSecretMessage; 1055 | 1056 | /** 业务所需的额外信息 */ 1057 | @property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; 1058 | 1059 | @end 1060 | 1061 | 1062 | 1063 | #pragma mark - WXAppExtendObject 1064 | /*! @brief 多媒体消息中包含的App扩展数据对象 1065 | * 1066 | * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, 1067 | * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 1068 | * @note url,extInfo和fileData不能同时为空 1069 | * @see WXMediaMessage 1070 | */ 1071 | @interface WXAppExtendObject : NSObject 1072 | /*! @brief 返回一个WXAppExtendObject对象 1073 | * 1074 | * @note 返回的WXAppExtendObject对象是自动释放的 1075 | */ 1076 | + (WXAppExtendObject *)object; 1077 | 1078 | /** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 1079 | * @note 长度不能超过10K 1080 | */ 1081 | @property (nonatomic, copy) NSString *url; 1082 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 1083 | * @note 长度不能超过2K 1084 | */ 1085 | @property (nonatomic, copy, nullable) NSString *extInfo; 1086 | /** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 1087 | * @note 大小不能超过10M 1088 | */ 1089 | @property (nonatomic, strong, nullable) NSData *fileData; 1090 | 1091 | @end 1092 | 1093 | 1094 | 1095 | #pragma mark - WXEmoticonObject 1096 | /*! @brief 多媒体消息中包含的表情数据对象 1097 | * 1098 | * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 1099 | * @see WXMediaMessage 1100 | */ 1101 | @interface WXEmoticonObject : NSObject 1102 | 1103 | /*! @brief 返回一个WXEmoticonObject对象 1104 | * 1105 | * @note 返回的WXEmoticonObject对象是自动释放的 1106 | */ 1107 | + (WXEmoticonObject *)object; 1108 | 1109 | /** 表情真实数据内容 1110 | * @note 大小不能超过10M 1111 | */ 1112 | @property (nonatomic, strong) NSData *emoticonData; 1113 | 1114 | @end 1115 | 1116 | 1117 | 1118 | #pragma mark - WXFileObject 1119 | /*! @brief 多媒体消息中包含的文件数据对象 1120 | * 1121 | * @see WXMediaMessage 1122 | */ 1123 | @interface WXFileObject : NSObject 1124 | 1125 | /*! @brief 返回一个WXFileObject对象 1126 | * 1127 | * @note 返回的WXFileObject对象是自动释放的 1128 | */ 1129 | + (WXFileObject *)object; 1130 | 1131 | /** 文件后缀名 1132 | * @note 长度不超过64字节 1133 | */ 1134 | @property (nonatomic, copy) NSString *fileExtension; 1135 | 1136 | /** 文件真实数据内容 1137 | * @note 大小不能超过10M 1138 | */ 1139 | @property (nonatomic, strong) NSData *fileData; 1140 | 1141 | @end 1142 | 1143 | 1144 | #pragma mark - WXLocationObject 1145 | /*! @brief 多媒体消息中包含的地理位置数据对象 1146 | * 1147 | * 微信终端和第三方程序之间传递消息中包含的地理位置数据对象。 1148 | * @see WXMediaMessage 1149 | */ 1150 | @interface WXLocationObject : NSObject 1151 | 1152 | /*! @brief 返回一个WXLocationObject对象 1153 | * 1154 | * @note 返回的WXLocationObject对象是自动释放的 1155 | */ 1156 | + (WXLocationObject *)object; 1157 | 1158 | /** 地理位置信息 1159 | * @note 经纬度 1160 | */ 1161 | @property (nonatomic, assign) double lng; //经度 1162 | @property (nonatomic, assign) double lat; //纬度 1163 | 1164 | @end 1165 | 1166 | #pragma mark - WXTextObject 1167 | /*! @brief 多媒体消息中包含的文本数据对象 1168 | * 1169 | * 微信终端和第三方程序之间传递消息中包含的文本数据对象。 1170 | * @see WXMediaMessage 1171 | */ 1172 | @interface WXTextObject : NSObject 1173 | 1174 | /*! @brief 返回一个WXTextObject对象 1175 | * 1176 | * @note 返回的WXTextObject对象是自动释放的 1177 | */ 1178 | + (WXTextObject *)object; 1179 | 1180 | /** 地理位置信息 1181 | * @note 文本内容 1182 | */ 1183 | @property (nonatomic, copy) NSString *contentText; 1184 | 1185 | @end 1186 | 1187 | #pragma mark - WXMiniProgramObject 1188 | 1189 | @interface WXMiniProgramObject : NSObject 1190 | 1191 | /*! @brief WXMiniProgramObject对象 1192 | * 1193 | * @note 返回的WXMiniProgramObject对象是自动释放的 1194 | */ 1195 | + (WXMiniProgramObject *)object; 1196 | 1197 | /** 低版本网页链接 1198 | * @attention 长度不能超过1024字节 1199 | */ 1200 | @property (nonatomic, copy) NSString *webpageUrl; 1201 | 1202 | /** 小程序username */ 1203 | @property (nonatomic, copy) NSString *userName; 1204 | 1205 | /** 小程序页面的路径 1206 | * @attention 不填默认拉起小程序首页 1207 | */ 1208 | @property (nonatomic, copy, nullable) NSString *path; 1209 | 1210 | /** 小程序新版本的预览图 1211 | * @attention 大小不能超过128k 1212 | */ 1213 | @property (nonatomic, strong, nullable) NSData *hdImageData; 1214 | 1215 | /** 是否使用带 shareTicket 的转发 */ 1216 | @property (nonatomic, assign) BOOL withShareTicket; 1217 | 1218 | /** 分享小程序的版本 1219 | * @attention (正式,开发,体验) 1220 | */ 1221 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; 1222 | 1223 | /** 是否禁用转发 */ 1224 | @property (nonatomic, assign) BOOL disableForward; 1225 | 1226 | @property (nonatomic, assign) BOOL isUpdatableMessage; 1227 | 1228 | @property (nonatomic, assign) BOOL isSecretMessage; 1229 | 1230 | 1231 | /** 业务所需的额外信息 */ 1232 | @property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; 1233 | 1234 | @end 1235 | 1236 | #pragma mark - WXGameLiveObject 1237 | 1238 | /*! @brief WXGameLiveObject对象 1239 | * 1240 | * @note 游戏直播消息类型 1241 | */ 1242 | 1243 | @interface WXGameLiveObject : NSObject 1244 | 1245 | + (WXGameLiveObject *)object; 1246 | 1247 | /** 业务所需的额外信息 */ 1248 | @property (nonatomic, strong, nullable) NSDictionary *extraInfoDic; 1249 | 1250 | @end 1251 | 1252 | @interface WXNativeGamePageObject : NSObject 1253 | 1254 | /** 是否为视频类型 1255 | */ 1256 | @property (nonatomic, assign) BOOL isVideo; 1257 | 1258 | /** 视频时长 1259 | @note 当为视频类型时,必填;单位为秒 1260 | */ 1261 | @property (nonatomic, assign) UInt32 videoDuration; 1262 | 1263 | /** 透传字段 1264 | @note 长度限制为100K 1265 | */ 1266 | @property (nonatomic, copy) NSString *shareData; 1267 | 1268 | /** 缩略图 1269 | @note 大小限制为256K 1270 | */ 1271 | @property (nonatomic, strong) NSData *gameThumbData; 1272 | 1273 | + (WXNativeGamePageObject *)object; 1274 | 1275 | @end 1276 | 1277 | #pragma mark - WXLaunchMiniProgramReq 1278 | 1279 | /*! @brief WXLaunchMiniProgramReq对象, 可实现通过sdk拉起微信小程序 1280 | * 1281 | * @note 返回的WXLaunchMiniProgramReq对象是自动释放的 1282 | */ 1283 | @interface WXLaunchMiniProgramReq : BaseReq 1284 | 1285 | + (WXLaunchMiniProgramReq *)object; 1286 | 1287 | /** 小程序username */ 1288 | @property (nonatomic, copy) NSString *userName; 1289 | 1290 | /** 小程序页面的路径 1291 | * @attention 不填默认拉起小程序首页 1292 | */ 1293 | @property (nonatomic, copy, nullable) NSString *path; 1294 | 1295 | /** 分享小程序的版本 1296 | * @attention (正式,开发,体验) 1297 | */ 1298 | @property (nonatomic, assign) WXMiniProgramType miniProgramType; 1299 | 1300 | /** ext信息 1301 | * @attention json格式 1302 | */ 1303 | @property (nonatomic, copy, nullable) NSString *extMsg; 1304 | 1305 | /** extDic 1306 | * @attention 字典,可存放图片等比较大的数据 1307 | */ 1308 | @property (nonatomic, copy, nullable) NSDictionary *extDic; 1309 | 1310 | @end 1311 | 1312 | #pragma mark - WXLaunchMiniProgramResp 1313 | /*! @brief 微信终端向第三方程序返回的WXLaunchMiniProgramReq处理结果。 1314 | * 1315 | * 第三方程序向微信终端发送WXLaunchMiniProgramReq后,微信发送回来的处理结果,该结果用WXLaunchMiniProgramResp表示。 1316 | */ 1317 | @interface WXLaunchMiniProgramResp : BaseResp 1318 | 1319 | @property (nonatomic, copy, nullable) NSString *extMsg; 1320 | 1321 | @end 1322 | 1323 | 1324 | #pragma mark - WXOpenBusinessViewReq 1325 | /*! @brief WXOpenBusinessViewReq对象, 可实现第三方通知微信启动,打开业务页面 1326 | * 1327 | * @note 返回的WXOpenBusinessViewReq对象是自动释放的 1328 | */ 1329 | 1330 | @interface WXOpenBusinessViewReq : BaseReq 1331 | 1332 | + (WXOpenBusinessViewReq *)object; 1333 | 1334 | /** 业务类型 1335 | */ 1336 | @property (nonatomic, copy) NSString *businessType; 1337 | 1338 | /** 业务参数 1339 | */ 1340 | @property (nonatomic, copy, nullable) NSString *query; 1341 | 1342 | /** ext信息 1343 | * @note 选填,json格式 1344 | */ 1345 | @property (nonatomic, copy, nullable) NSString *extInfo; 1346 | 1347 | /** extData数据 1348 | * @note 1349 | */ 1350 | @property (nonatomic, strong, nullable) NSData *extData; 1351 | @end 1352 | 1353 | 1354 | @interface WXOpenBusinessViewResp : BaseResp 1355 | 1356 | /** 业务类型 1357 | */ 1358 | @property (nonatomic, copy) NSString *businessType; 1359 | 1360 | /** 业务返回数据 1361 | */ 1362 | @property (nonatomic, copy, nullable) NSString *extMsg; 1363 | 1364 | @end 1365 | 1366 | #pragma mark - WXOpenCustomerServiceReq 1367 | @interface WXOpenCustomerServiceReq : BaseReq 1368 | 1369 | + (WXOpenCustomerServiceReq *)object; 1370 | 1371 | /**企微客服发起流程 url 1372 | */ 1373 | @property (nonatomic, copy, nullable) NSString *url; 1374 | 1375 | /**企业 id 1376 | */ 1377 | @property (nonatomic, copy, nullable) NSString *corpid; 1378 | 1379 | @end 1380 | 1381 | @interface WXOpenCustomerServiceResp : BaseResp 1382 | 1383 | /** 业务返回数据 1384 | */ 1385 | @property (nonatomic, copy, nullable) NSString *extMsg; 1386 | 1387 | @end 1388 | 1389 | 1390 | #pragma mark - WXChannelStartLiveReq 1391 | 1392 | @interface WXChannelStartLiveReq : BaseReq 1393 | 1394 | + (WXChannelStartLiveReq *)object; 1395 | 1396 | /** 必填,直播业务数据(json格式) 1397 | */ 1398 | @property (nonatomic, copy) NSString *liveJsonInfo; 1399 | 1400 | @end 1401 | 1402 | @interface WXChannelStartLiveResp : BaseResp 1403 | 1404 | /** 业务返回数据 1405 | */ 1406 | @property (nonatomic, copy, nullable) NSString *extMsg; 1407 | 1408 | @end 1409 | 1410 | NS_ASSUME_NONNULL_END 1411 | -------------------------------------------------------------------------------- /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.graphics.BitmapFactory; 7 | import android.net.Uri; 8 | import android.util.Log; 9 | 10 | import androidx.annotation.Nullable; 11 | 12 | import com.facebook.common.executors.UiThreadImmediateExecutorService; 13 | import com.facebook.common.references.CloseableReference; 14 | import com.facebook.common.util.UriUtil; 15 | import com.facebook.datasource.DataSource; 16 | import com.facebook.drawee.backends.pipeline.Fresco; 17 | import com.facebook.imagepipeline.common.ResizeOptions; 18 | import com.facebook.imagepipeline.core.ImagePipeline; 19 | import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber; 20 | import com.facebook.imagepipeline.image.CloseableImage; 21 | import com.facebook.imagepipeline.request.ImageRequest; 22 | import com.facebook.imagepipeline.request.ImageRequestBuilder; 23 | import com.facebook.react.bridge.Arguments; 24 | import com.facebook.react.bridge.Callback; 25 | import com.facebook.react.bridge.ReactApplicationContext; 26 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 27 | import com.facebook.react.bridge.ReactMethod; 28 | import com.facebook.react.bridge.ReadableMap; 29 | import com.facebook.react.bridge.WritableMap; 30 | import com.facebook.react.modules.core.DeviceEventManagerModule; 31 | import com.tencent.mm.opensdk.modelbase.BaseReq; 32 | import com.tencent.mm.opensdk.modelbase.BaseResp; 33 | import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat; 34 | import com.tencent.mm.opensdk.modelmsg.SendAuth; 35 | import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; 36 | import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX; 37 | import com.tencent.mm.opensdk.modelmsg.WXFileObject; 38 | import com.tencent.mm.opensdk.modelmsg.WXImageObject; 39 | import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; 40 | import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject; 41 | import com.tencent.mm.opensdk.modelmsg.WXMusicObject; 42 | import com.tencent.mm.opensdk.modelmsg.WXTextObject; 43 | import com.tencent.mm.opensdk.modelmsg.WXVideoObject; 44 | import com.tencent.mm.opensdk.modelmsg.WXWebpageObject; 45 | import com.tencent.mm.opensdk.modelpay.PayReq; 46 | import com.tencent.mm.opensdk.modelpay.PayResp; 47 | import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram; 48 | import com.tencent.mm.opensdk.openapi.IWXAPI; 49 | import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; 50 | import com.tencent.mm.opensdk.openapi.WXAPIFactory; 51 | import com.tencent.mm.opensdk.constants.ConstantsAPI; 52 | import com.tencent.mm.opensdk.modelbiz.SubscribeMessage; 53 | 54 | import java.io.ByteArrayOutputStream; 55 | import java.io.FileInputStream; 56 | import java.io.FileNotFoundException; 57 | import java.util.ArrayList; 58 | import java.util.UUID; 59 | 60 | public class WeChatModule extends ReactContextBaseJavaModule implements IWXAPIEventHandler { 61 | private String appId; 62 | 63 | private IWXAPI api = null; 64 | private final static String NOT_REGISTERED = "registerApp required."; 65 | private final static String INVOKE_FAILED = "WeChat API invoke returns false."; 66 | private final static String INVALID_ARGUMENT = "invalid argument."; 67 | // 缩略图大小 kb 68 | private final static int THUMB_SIZE = 32; 69 | private static Intent cacheLaunchIntent; // 缓存,只用于handleLaunchAppReq 70 | private boolean hasHandleLaunch = false; // 是否执行过handleLaunchAppReq 71 | 72 | private static byte[] bitmapTopBytes(Bitmap bitmap) { 73 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 74 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 75 | bitmap.recycle(); 76 | return baos.toByteArray(); 77 | } 78 | 79 | private static byte[] bitmapResizeGetBytes(Bitmap image, int size) { 80 | // little-snow-fox 2019.10.20 81 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 82 | // 质量压缩方法,这里100表示第一次不压缩,把压缩后的数据缓存到 baos 83 | image.compress(Bitmap.CompressFormat.JPEG, 100, baos); 84 | int options = 100; 85 | // 循环判断压缩后依然大于 32kb 则继续压缩 86 | while (baos.toByteArray().length / 1024 > size) { 87 | // 重置baos即清空baos 88 | baos.reset(); 89 | if (options > 10) { 90 | options -= 8; 91 | } else { 92 | int dstHeight = getDstHeight(image); 93 | return bitmapResizeGetBytes(Bitmap.createScaledBitmap(image, 280, dstHeight, true), size); 94 | } 95 | // 这里压缩options%,把压缩后的数据存放到baos中 96 | image.compress(Bitmap.CompressFormat.JPEG, options, baos); 97 | } 98 | return baos.toByteArray(); 99 | } 100 | 101 | private static int getDstHeight(Bitmap image) { 102 | int dstHeight = image.getHeight() / image.getWidth() * 280; 103 | if (dstHeight <= 0) { 104 | dstHeight = image.getHeight() * 280 / image.getWidth(); 105 | } 106 | if (dstHeight <= 0) { 107 | dstHeight = 280; 108 | } 109 | return dstHeight; 110 | } 111 | 112 | public WeChatModule(ReactApplicationContext context) { 113 | super(context); 114 | } 115 | 116 | @Override 117 | public String getName() { 118 | return "RCTWeChat"; 119 | } 120 | 121 | /** 122 | * fix Native module WeChatModule tried to override WeChatModule for module name RCTWeChat. 123 | * If this was your intention, return true from WeChatModule#canOverrideExistingModule() bug 124 | * 125 | * @return 126 | */ 127 | public boolean canOverrideExistingModule() { 128 | return true; 129 | } 130 | 131 | private static ArrayList modules = new ArrayList<>(); 132 | 133 | @Override 134 | public void initialize() { 135 | super.initialize(); 136 | modules.add(this); 137 | } 138 | 139 | @Override 140 | public void onCatalystInstanceDestroy() { 141 | super.onCatalystInstanceDestroy(); 142 | if (api != null) { 143 | api = null; 144 | } 145 | modules.remove(this); 146 | } 147 | 148 | public static void handleIntent(Intent intent) { 149 | for (WeChatModule mod : modules) { 150 | mod.api.handleIntent(intent, mod); 151 | } 152 | } 153 | 154 | @ReactMethod 155 | public void registerApp(String appid, String universalLink, Callback callback) { 156 | this.appId = appid; 157 | api = WXAPIFactory.createWXAPI(this.getReactApplicationContext().getBaseContext(), appid, true); 158 | callback.invoke(null, api.registerApp(appid)); 159 | } 160 | 161 | @ReactMethod 162 | public void isWXAppInstalled(Callback callback) { 163 | if (api == null) { 164 | callback.invoke(NOT_REGISTERED); 165 | return; 166 | } 167 | callback.invoke(null, api.isWXAppInstalled()); 168 | } 169 | 170 | @ReactMethod 171 | public void isWXAppSupportApi(Callback callback) { 172 | if (api == null) { 173 | callback.invoke(NOT_REGISTERED); 174 | return; 175 | } 176 | callback.invoke(null, api.getWXAppSupportAPI()); 177 | } 178 | 179 | @ReactMethod 180 | public void getApiVersion(Callback callback) { 181 | if (api == null) { 182 | callback.invoke(NOT_REGISTERED); 183 | return; 184 | } 185 | callback.invoke(null, api.getWXAppSupportAPI()); 186 | } 187 | 188 | @ReactMethod 189 | public void openWXApp(Callback callback) { 190 | if (api == null) { 191 | callback.invoke(NOT_REGISTERED); 192 | return; 193 | } 194 | callback.invoke(null, api.openWXApp()); 195 | } 196 | 197 | @ReactMethod 198 | public void sendAuthRequest(String scope, String state, Callback callback) { 199 | if (api == null) { 200 | callback.invoke(NOT_REGISTERED); 201 | return; 202 | } 203 | SendAuth.Req req = new SendAuth.Req(); 204 | req.scope = scope; 205 | req.state = state; 206 | callback.invoke(null, api.sendReq(req)); 207 | } 208 | 209 | /** 210 | * 分享文本 211 | * 212 | * @param data 213 | * @param callback 214 | */ 215 | @ReactMethod 216 | public void shareText(ReadableMap data, Callback callback) { 217 | //初始化一个 WXTextObject 对象,填写分享的文本内容 218 | WXTextObject textObj = new WXTextObject(); 219 | textObj.text = data.getString("text"); 220 | 221 | //用 WXTextObject 对象初始化一个 WXMediaMessage 对象 222 | WXMediaMessage msg = new WXMediaMessage(); 223 | msg.mediaObject = textObj; 224 | msg.description = data.getString("text"); 225 | 226 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 227 | req.transaction = "text"; 228 | req.message = msg; 229 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 230 | callback.invoke(null, api.sendReq(req)); 231 | } 232 | 233 | /** 234 | * 分享图片 235 | * 236 | * @param data 237 | * @param callback 238 | */ 239 | @ReactMethod 240 | public void shareImage(final ReadableMap data, final Callback callback) { 241 | this._getImage(Uri.parse(data.getString("imageUrl")), null, new ImageCallback() { 242 | @Override 243 | public void invoke(@Nullable Bitmap bitmap) { 244 | Bitmap bmp = bitmap; 245 | int maxWidth = data.hasKey("maxWidth") ? data.getInt("maxWidth") : -1; 246 | if (maxWidth > 0) { 247 | bmp = Bitmap.createScaledBitmap(bmp, maxWidth, bmp.getHeight() / bmp.getWidth() * maxWidth, true); 248 | } 249 | // 初始化 WXImageObject 和 WXMediaMessage 对象 250 | WXImageObject imgObj = new WXImageObject(bmp); 251 | WXMediaMessage msg = new WXMediaMessage(); 252 | msg.mediaObject = imgObj; 253 | 254 | // 设置缩略图 255 | msg.thumbData = bitmapResizeGetBytes(bmp, THUMB_SIZE); 256 | 257 | // 构造一个Req 258 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 259 | req.transaction = "img"; 260 | req.message = msg; 261 | // req.userOpenId = getOpenId(); 262 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 263 | callback.invoke(null, api.sendReq(req)); 264 | } 265 | }); 266 | 267 | } 268 | // private static final String SDCARD_ROOT = Environment.getExternalStorageDirectory().getAbsolutePath(); 269 | 270 | /** 271 | * 分享本地图片 272 | * 273 | * @param data 274 | * @param callback 275 | */ 276 | @ReactMethod 277 | public void shareLocalImage(final ReadableMap data, final Callback callback) { 278 | FileInputStream fs = null; 279 | try { 280 | String path = data.getString("imageUrl"); 281 | if (path.indexOf("file://") > -1) { 282 | path = path.substring(7); 283 | } 284 | // int maxWidth = data.hasKey("maxWidth") ? data.getInt("maxWidth") : -1; 285 | fs = new FileInputStream(path); 286 | Bitmap bmp = BitmapFactory.decodeStream(fs); 287 | 288 | // if (maxWidth > 0) { 289 | // bmp = Bitmap.createScaledBitmap(bmp, maxWidth, bmp.getHeight() / bmp.getWidth() * maxWidth, true); 290 | // } 291 | 292 | // File f = Environment.getExternalStoragePublicDirectory(SDCARD_ROOT + "/react-native-wechat-lib"); 293 | // String fileName = "wechat-share.jpg"; 294 | // String tempPath = SDCARD_ROOT + "/react-native-wechat-lib"; 295 | // File file = new File(f, fileName); 296 | // try { 297 | // FileOutputStream fos = new FileOutputStream(file); 298 | // bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); 299 | // fos.flush(); 300 | // fos.close(); 301 | // } catch (FileNotFoundException e) { 302 | // e.printStackTrace(); 303 | // } catch (IOException e) { 304 | // e.printStackTrace(); 305 | // } 306 | 307 | // int size = bmp.getByteCount(); 308 | // ByteArrayOutputStream var2 = new ByteArrayOutputStream(); 309 | // bmp.compress(Bitmap.CompressFormat.JPEG, 85, var2); 310 | // int size2 = var2.toByteArray().length; 311 | // 初始化 WXImageObject 和 WXMediaMessage 对象 312 | 313 | WXImageObject imgObj = new WXImageObject(bmp); 314 | WXMediaMessage msg = new WXMediaMessage(); 315 | msg.mediaObject = imgObj; 316 | // 设置缩略图 317 | msg.thumbData = bitmapResizeGetBytes(bmp, THUMB_SIZE); 318 | bmp.recycle(); 319 | // 构造一个Req 320 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 321 | req.transaction = "img"; 322 | req.message = msg; 323 | // req.userOpenId = getOpenId(); 324 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 325 | callback.invoke(null, api.sendReq(req)); 326 | } catch (FileNotFoundException e) { 327 | callback.invoke(null, false); 328 | e.printStackTrace(); 329 | } 330 | } 331 | 332 | /** 333 | * 分享音乐 334 | * 335 | * @param data 336 | * @param callback 337 | */ 338 | @ReactMethod 339 | public void shareMusic(final ReadableMap data, final Callback callback) { 340 | // 初始化一个WXMusicObject,填写url 341 | WXMusicObject music = new WXMusicObject(); 342 | music.musicUrl = data.hasKey("musicUrl") ? data.getString("musicUrl") : null; 343 | music.musicLowBandUrl = data.hasKey("musicLowBandUrl") ? data.getString("musicLowBandUrl") : null; 344 | music.musicDataUrl = data.hasKey("musicDataUrl") ? data.getString("musicDataUrl") : null; 345 | music.musicUrl = data.hasKey("musicUrl") ? data.getString("musicUrl") : null; 346 | music.musicLowBandDataUrl = data.hasKey("musicLowBandDataUrl") ? data.getString("musicLowBandDataUrl") : null; 347 | // 用 WXMusicObject 对象初始化一个 WXMediaMessage 对象 348 | final WXMediaMessage msg = new WXMediaMessage(); 349 | msg.mediaObject = music; 350 | msg.title = data.hasKey("title") ? data.getString("title") : null; 351 | msg.description = data.hasKey("description") ? data.getString("description") : null; 352 | 353 | if (data.hasKey("thumbImageUrl")) { 354 | this._getImage(Uri.parse(data.getString("thumbImageUrl")), null, new ImageCallback() { 355 | @Override 356 | public void invoke(@Nullable Bitmap bmp) { 357 | // 设置缩略图 358 | if (bmp != null) { 359 | msg.thumbData = bitmapResizeGetBytes(bmp, THUMB_SIZE); 360 | } 361 | // 构造一个Req 362 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 363 | req.transaction = "music"; 364 | req.message = msg; 365 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 366 | callback.invoke(null, api.sendReq(req)); 367 | } 368 | }); 369 | } else { 370 | // 构造一个Req 371 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 372 | req.transaction = "music"; 373 | req.message = msg; 374 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 375 | callback.invoke(null, api.sendReq(req)); 376 | } 377 | 378 | } 379 | 380 | /** 381 | * 分享视频 382 | * 383 | * @param data 384 | * @param callback 385 | */ 386 | @ReactMethod 387 | public void shareVideo(final ReadableMap data, final Callback callback) { 388 | // 初始化一个WXVideoObject,填写url 389 | WXVideoObject video = new WXVideoObject(); 390 | video.videoUrl = data.hasKey("videoUrl") ? data.getString("videoUrl") : null; 391 | video.videoLowBandUrl = data.hasKey("videoLowBandUrl") ? data.getString("videoLowBandUrl") : null; 392 | //用 WXVideoObject 对象初始化一个 WXMediaMessage 对象 393 | final WXMediaMessage msg = new WXMediaMessage(video); 394 | msg.title = data.hasKey("title") ? data.getString("title") : null; 395 | msg.description = data.hasKey("description") ? data.getString("description") : null; 396 | 397 | if (data.hasKey("thumbImageUrl")) { 398 | this._getImage(Uri.parse(data.getString("thumbImageUrl")), null, new ImageCallback() { 399 | @Override 400 | public void invoke(@Nullable Bitmap bmp) { 401 | // 设置缩略图 402 | if (bmp != null) { 403 | msg.thumbData = bitmapResizeGetBytes(bmp, THUMB_SIZE); 404 | } 405 | // 构造一个Req 406 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 407 | req.transaction = "video"; 408 | req.message = msg; 409 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 410 | callback.invoke(null, api.sendReq(req)); 411 | } 412 | }); 413 | } else { 414 | // 构造一个Req 415 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 416 | req.transaction = "video"; 417 | req.message = msg; 418 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 419 | callback.invoke(null, api.sendReq(req)); 420 | } 421 | } 422 | 423 | /** 424 | * 分享网页 425 | * 426 | * @param data 427 | * @param callback 428 | */ 429 | @ReactMethod 430 | public void shareWebpage(final ReadableMap data, final Callback callback) { 431 | // 初始化一个WXWebpageObject,填写url 432 | WXWebpageObject webpage = new WXWebpageObject(); 433 | webpage.webpageUrl = data.hasKey("webpageUrl") ? data.getString("webpageUrl") : null; 434 | 435 | //用 WXWebpageObject 对象初始化一个 WXMediaMessage 对象 436 | final WXMediaMessage msg = new WXMediaMessage(webpage); 437 | msg.title = data.hasKey("title") ? data.getString("title") : null; 438 | msg.description = data.hasKey("description") ? data.getString("description") : null; 439 | 440 | if (data.hasKey("thumbImageUrl")) { 441 | this._getImage(Uri.parse(data.getString("thumbImageUrl")), null, new ImageCallback() { 442 | @Override 443 | public void invoke(@Nullable Bitmap bmp) { 444 | // 设置缩略图 445 | if (bmp != null) { 446 | msg.thumbData = bitmapResizeGetBytes(bmp, THUMB_SIZE); 447 | } 448 | // 构造一个Req 449 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 450 | req.transaction = "webpage"; 451 | req.message = msg; 452 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 453 | callback.invoke(null, api.sendReq(req)); 454 | } 455 | }); 456 | } else { 457 | // 构造一个Req 458 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 459 | req.transaction = "webpage"; 460 | req.message = msg; 461 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 462 | callback.invoke(null, api.sendReq(req)); 463 | } 464 | } 465 | 466 | /** 467 | * 分享小程序 468 | * 469 | * @param data 470 | * @param callback 471 | */ 472 | @ReactMethod 473 | public void shareMiniProgram(final ReadableMap data, final Callback callback) { 474 | WXMiniProgramObject miniProgramObj = new WXMiniProgramObject(); 475 | // 兼容低版本的网页链接 476 | miniProgramObj.webpageUrl = data.hasKey("webpageUrl") ? data.getString("webpageUrl") : null; 477 | // 正式版:0,测试版:1,体验版:2 478 | miniProgramObj.miniprogramType = data.hasKey("miniprogramType") ? data.getInt("miniprogramType") : WXMiniProgramObject.MINIPTOGRAM_TYPE_RELEASE; 479 | // 小程序原始id 480 | miniProgramObj.userName = data.hasKey("userName") ? data.getString("userName") : null; 481 | // 小程序页面路径;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar" 482 | miniProgramObj.path = data.hasKey("path") ? data.getString("path") : null; 483 | final WXMediaMessage msg = new WXMediaMessage(miniProgramObj); 484 | // 小程序消息 title 485 | msg.title = data.hasKey("title") ? data.getString("title") : null; 486 | // 小程序消息 desc 487 | msg.description = data.hasKey("description") ? data.getString("description") : null; 488 | 489 | String thumbImageUrl = data.hasKey("hdImageUrl") ? data.getString("hdImageUrl") : data.hasKey("thumbImageUrl") ? data.getString("thumbImageUrl") : null; 490 | 491 | if (thumbImageUrl != null && !thumbImageUrl.equals("")) { 492 | this._getImage(Uri.parse(thumbImageUrl), null, new ImageCallback() { 493 | @Override 494 | public void invoke(@Nullable Bitmap bmp) { 495 | // 小程序消息封面图片,小于128k 496 | if (bmp != null) { 497 | msg.thumbData = bitmapResizeGetBytes(bmp, 128); 498 | } 499 | // 构造一个Req 500 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 501 | req.transaction = "miniProgram"; 502 | req.message = msg; 503 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 504 | callback.invoke(null, api.sendReq(req)); 505 | } 506 | }); 507 | } else { 508 | // 构造一个Req 509 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 510 | req.transaction = "miniProgram"; 511 | req.message = msg; 512 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 513 | callback.invoke(null, api.sendReq(req)); 514 | } 515 | } 516 | 517 | @ReactMethod 518 | public void shareToTimeline(ReadableMap data, Callback callback) { 519 | if (api == null) { 520 | callback.invoke(NOT_REGISTERED); 521 | return; 522 | } 523 | _share(SendMessageToWX.Req.WXSceneTimeline, data, callback); 524 | } 525 | 526 | @ReactMethod 527 | public void launchMiniProgram(ReadableMap data, Callback callback) { 528 | if (api == null) { 529 | callback.invoke(NOT_REGISTERED); 530 | return; 531 | } 532 | WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req(); 533 | // 填小程序原始id 534 | req.userName = data.getString("userName"); 535 | //拉起小程序页面的可带参路径,不填默认拉起小程序首页 536 | req.path = data.getString("path"); 537 | // 可选打开 开发版,体验版和正式版 538 | req.miniprogramType = data.getInt("miniProgramType"); 539 | boolean success = api.sendReq(req); 540 | if (!success) callback.invoke(INVALID_ARGUMENT); 541 | } 542 | 543 | /** 544 | * 一次性订阅消息 545 | * 546 | * @param data 547 | * @param callback 548 | */ 549 | @ReactMethod 550 | public void subscribeMessage(ReadableMap data, Callback callback) { 551 | SubscribeMessage.Req req = new SubscribeMessage.Req(); 552 | req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession; 553 | req.templateID = data.getString("templateId"); 554 | req.reserved = data.getString("reserved"); 555 | callback.invoke(null, api.sendReq(req)); 556 | } 557 | 558 | @ReactMethod 559 | public void shareToSession(ReadableMap data, Callback callback) { 560 | if (api == null) { 561 | callback.invoke(NOT_REGISTERED); 562 | return; 563 | } 564 | _share(SendMessageToWX.Req.WXSceneSession, data, callback); 565 | } 566 | 567 | @ReactMethod 568 | public void shareToFavorite(ReadableMap data, Callback callback) { 569 | if (api == null) { 570 | callback.invoke(NOT_REGISTERED); 571 | return; 572 | } 573 | _share(SendMessageToWX.Req.WXSceneFavorite, data, callback); 574 | } 575 | 576 | @ReactMethod 577 | public void pay(ReadableMap data, Callback callback) { 578 | PayReq payReq = new PayReq(); 579 | if (data.hasKey("partnerId")) { 580 | payReq.partnerId = data.getString("partnerId"); 581 | } 582 | if (data.hasKey("prepayId")) { 583 | payReq.prepayId = data.getString("prepayId"); 584 | } 585 | if (data.hasKey("nonceStr")) { 586 | payReq.nonceStr = data.getString("nonceStr"); 587 | } 588 | if (data.hasKey("timeStamp")) { 589 | payReq.timeStamp = data.getString("timeStamp"); 590 | } 591 | if (data.hasKey("sign")) { 592 | payReq.sign = data.getString("sign"); 593 | } 594 | if (data.hasKey("package")) { 595 | payReq.packageValue = data.getString("package"); 596 | } 597 | if (data.hasKey("extData")) { 598 | payReq.extData = data.getString("extData"); 599 | } 600 | payReq.appId = appId; 601 | callback.invoke(api.sendReq(payReq) ? null : INVOKE_FAILED); 602 | } 603 | 604 | @ReactMethod 605 | public void openCustomerServiceChat(ReadableMap data, Callback callback) { 606 | if (api == null) { 607 | callback.invoke(NOT_REGISTERED); 608 | return; 609 | } 610 | 611 | WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req(); 612 | if (data.hasKey("corpId")) { 613 | req.corpId = data.getString("corpId"); 614 | } 615 | if (data.hasKey("url")) { 616 | req.url = data.getString("url"); 617 | } 618 | callback.invoke(null, api.sendReq(req)); 619 | } 620 | 621 | /** 622 | * 因为启动时js还未准备好,需要手动触发下 623 | */ 624 | @ReactMethod 625 | public void handleLaunchAppReq() { 626 | hasHandleLaunch = true; 627 | if (cacheLaunchIntent != null) { 628 | WeChatModule.handleIntent(cacheLaunchIntent); 629 | } 630 | } 631 | 632 | /** 633 | * 缓存启动时微信传过来的信息,在WXEntryActivity中调用 634 | * 635 | * @param launchIntent 636 | */ 637 | public static void handleLaunchIntent(Intent launchIntent) { 638 | cacheLaunchIntent = launchIntent;//缓存数据 639 | } 640 | 641 | private void _share(final int scene, final ReadableMap data, final Callback callback) { 642 | Uri uri = null; 643 | if (data.hasKey("thumbImage")) { 644 | String imageUrl = data.getString("thumbImage"); 645 | 646 | try { 647 | uri = Uri.parse(imageUrl); 648 | // Verify scheme is set, so that relative uri (used by static resources) are not handled. 649 | if (uri.getScheme() == null) { 650 | uri = getResourceDrawableUri(getReactApplicationContext(), imageUrl); 651 | } 652 | } catch (Exception e) { 653 | // ignore malformed uri, then attempt to extract resource ID. 654 | } 655 | } 656 | 657 | if (uri != null) { 658 | this._getImage(uri, new ResizeOptions(100, 100), new ImageCallback() { 659 | @Override 660 | public void invoke(@Nullable Bitmap bitmap) { 661 | WeChatModule.this._share(scene, data, bitmap, callback); 662 | } 663 | }); 664 | } else { 665 | this._share(scene, data, null, callback); 666 | } 667 | } 668 | 669 | private void _getImage(Uri uri, ResizeOptions resizeOptions, final ImageCallback imageCallback) { 670 | BaseBitmapDataSubscriber dataSubscriber = new BaseBitmapDataSubscriber() { 671 | @Override 672 | protected void onNewResultImpl(Bitmap bitmap) { 673 | if (bitmap != null) { 674 | if (bitmap.getConfig() != null) { 675 | bitmap = bitmap.copy(bitmap.getConfig(), true); 676 | imageCallback.invoke(bitmap); 677 | } else { 678 | bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); 679 | imageCallback.invoke(bitmap); 680 | } 681 | } else { 682 | imageCallback.invoke(null); 683 | } 684 | } 685 | 686 | @Override 687 | protected void onFailureImpl(DataSource> dataSource) { 688 | imageCallback.invoke(null); 689 | } 690 | }; 691 | 692 | ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri); 693 | if (resizeOptions != null) { 694 | builder = builder.setResizeOptions(resizeOptions); 695 | } 696 | ImageRequest imageRequest = builder.build(); 697 | 698 | ImagePipeline imagePipeline = Fresco.getImagePipeline(); 699 | DataSource> dataSource = imagePipeline.fetchDecodedImage(imageRequest, null); 700 | dataSource.subscribe(dataSubscriber, UiThreadImmediateExecutorService.getInstance()); 701 | } 702 | 703 | private static Uri getResourceDrawableUri(Context context, String name) { 704 | if (name == null || name.isEmpty()) { 705 | return null; 706 | } 707 | name = name.toLowerCase().replace("-", "_"); 708 | int resId = context.getResources().getIdentifier(name, "drawable", context.getPackageName()); 709 | 710 | if (resId == 0) { 711 | return null; 712 | } else { 713 | return new Uri.Builder().scheme(UriUtil.LOCAL_RESOURCE_SCHEME).path(String.valueOf(resId)).build(); 714 | } 715 | } 716 | 717 | private void _share(final int scene, final ReadableMap data, final Bitmap thumbImage, final Callback callback) { 718 | if (!data.hasKey("type")) { 719 | callback.invoke(INVALID_ARGUMENT); 720 | return; 721 | } 722 | String type = data.getString("type"); 723 | 724 | WXMediaMessage.IMediaObject mediaObject = null; 725 | if (type.equals("news")) { 726 | mediaObject = _jsonToWebpageMedia(data); 727 | } else if (type.equals("text")) { 728 | mediaObject = _jsonToTextMedia(data); 729 | } else if (type.equals("imageUrl") || type.equals("imageResource")) { 730 | __jsonToImageUrlMedia(data, new MediaObjectCallback() { 731 | @Override 732 | public void invoke(@Nullable WXMediaMessage.IMediaObject mediaObject) { 733 | if (mediaObject == null) { 734 | callback.invoke(INVALID_ARGUMENT); 735 | } else { 736 | WeChatModule.this._share(scene, data, thumbImage, mediaObject, callback); 737 | } 738 | } 739 | }); 740 | return; 741 | } else if (type.equals("imageFile")) { 742 | __jsonToImageFileMedia(data, new MediaObjectCallback() { 743 | @Override 744 | public void invoke(@Nullable WXMediaMessage.IMediaObject mediaObject) { 745 | if (mediaObject == null) { 746 | callback.invoke(INVALID_ARGUMENT); 747 | } else { 748 | WeChatModule.this._share(scene, data, thumbImage, mediaObject, callback); 749 | } 750 | } 751 | }); 752 | return; 753 | } else if (type.equals("video")) { 754 | mediaObject = __jsonToVideoMedia(data); 755 | } else if (type.equals("audio")) { 756 | mediaObject = __jsonToMusicMedia(data); 757 | } else if (type.equals("file")) { 758 | mediaObject = __jsonToFileMedia(data); 759 | } 760 | 761 | if (mediaObject == null) { 762 | callback.invoke(INVALID_ARGUMENT); 763 | } else { 764 | _share(scene, data, thumbImage, mediaObject, callback); 765 | } 766 | } 767 | 768 | private void _share(int scene, ReadableMap data, Bitmap thumbImage, WXMediaMessage.IMediaObject mediaObject, Callback callback) { 769 | 770 | WXMediaMessage message = new WXMediaMessage(); 771 | message.mediaObject = mediaObject; 772 | 773 | if (thumbImage != null) { 774 | message.setThumbImage(thumbImage); 775 | } 776 | 777 | if (data.hasKey("title")) { 778 | message.title = data.getString("title"); 779 | } 780 | if (data.hasKey("description")) { 781 | message.description = data.getString("description"); 782 | } 783 | if (data.hasKey("mediaTagName")) { 784 | message.mediaTagName = data.getString("mediaTagName"); 785 | } 786 | if (data.hasKey("messageAction")) { 787 | message.messageAction = data.getString("messageAction"); 788 | } 789 | if (data.hasKey("messageExt")) { 790 | message.messageExt = data.getString("messageExt"); 791 | } 792 | 793 | SendMessageToWX.Req req = new SendMessageToWX.Req(); 794 | req.message = message; 795 | req.scene = scene; 796 | req.transaction = UUID.randomUUID().toString(); 797 | callback.invoke(null, api.sendReq(req)); 798 | } 799 | 800 | private WXTextObject _jsonToTextMedia(ReadableMap data) { 801 | if (!data.hasKey("description")) { 802 | return null; 803 | } 804 | 805 | WXTextObject ret = new WXTextObject(); 806 | ret.text = data.getString("description"); 807 | return ret; 808 | } 809 | 810 | private WXWebpageObject _jsonToWebpageMedia(ReadableMap data) { 811 | if (!data.hasKey("webpageUrl")) { 812 | return null; 813 | } 814 | 815 | WXWebpageObject ret = new WXWebpageObject(); 816 | ret.webpageUrl = data.getString("webpageUrl"); 817 | if (data.hasKey("extInfo")) { 818 | ret.extInfo = data.getString("extInfo"); 819 | } 820 | return ret; 821 | } 822 | 823 | private void __jsonToImageMedia(String imageUrl, final MediaObjectCallback callback) { 824 | Uri imageUri; 825 | try { 826 | imageUri = Uri.parse(imageUrl); 827 | // Verify scheme is set, so that relative uri (used by static resources) are not handled. 828 | if (imageUri.getScheme() == null) { 829 | imageUri = getResourceDrawableUri(getReactApplicationContext(), imageUrl); 830 | } 831 | } catch (Exception e) { 832 | imageUri = null; 833 | } 834 | 835 | if (imageUri == null) { 836 | callback.invoke(null); 837 | return; 838 | } 839 | 840 | this._getImage(imageUri, null, new ImageCallback() { 841 | @Override 842 | public void invoke(@Nullable Bitmap bitmap) { 843 | callback.invoke(bitmap == null ? null : new WXImageObject(bitmap)); 844 | } 845 | }); 846 | } 847 | 848 | private void __jsonToImageUrlMedia(ReadableMap data, MediaObjectCallback callback) { 849 | if (!data.hasKey("imageUrl")) { 850 | callback.invoke(null); 851 | return; 852 | } 853 | String imageUrl = data.getString("imageUrl"); 854 | __jsonToImageMedia(imageUrl, callback); 855 | } 856 | 857 | private void __jsonToImageFileMedia(ReadableMap data, MediaObjectCallback callback) { 858 | if (!data.hasKey("imageUrl")) { 859 | callback.invoke(null); 860 | return; 861 | } 862 | 863 | String imageUrl = data.getString("imageUrl"); 864 | if (!imageUrl.toLowerCase().startsWith("file://")) { 865 | imageUrl = "file://" + imageUrl; 866 | } 867 | __jsonToImageMedia(imageUrl, callback); 868 | } 869 | 870 | private WXMusicObject __jsonToMusicMedia(ReadableMap data) { 871 | if (!data.hasKey("musicUrl")) { 872 | return null; 873 | } 874 | 875 | WXMusicObject ret = new WXMusicObject(); 876 | ret.musicUrl = data.getString("musicUrl"); 877 | return ret; 878 | } 879 | 880 | private WXVideoObject __jsonToVideoMedia(ReadableMap data) { 881 | if (!data.hasKey("videoUrl")) { 882 | return null; 883 | } 884 | 885 | WXVideoObject ret = new WXVideoObject(); 886 | ret.videoUrl = data.getString("videoUrl"); 887 | return ret; 888 | } 889 | 890 | private WXFileObject __jsonToFileMedia(ReadableMap data) { 891 | if (!data.hasKey("filePath")) { 892 | return null; 893 | } 894 | return new WXFileObject(data.getString("filePath")); 895 | } 896 | 897 | // TODO: 实现sendRequest、sendSuccessResponse、sendErrorCommonResponse、sendErrorUserCancelResponse 898 | 899 | @Override 900 | public void onReq(BaseReq baseReq) { 901 | WritableMap map = Arguments.createMap(); 902 | map.putString("openId", baseReq.openId); 903 | map.putString("transaction", baseReq.transaction); 904 | if (baseReq.getType() == ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX) { 905 | ShowMessageFromWX.Req req = (ShowMessageFromWX.Req) baseReq; 906 | // 对应JsApi navigateBackApplication中的extraData字段数据 907 | map.putString("type", "LaunchFromWX.Req"); 908 | map.putString("lang", req.lang); 909 | map.putString("country", req.country); 910 | map.putString("extMsg", req.message.messageExt); 911 | } 912 | this.getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("WeChat_Req", map); 913 | // 未处理过handleLaunchAppReq,不做清除缓存 914 | if (hasHandleLaunch) { 915 | cacheLaunchIntent = null; 916 | } 917 | } 918 | 919 | @Override 920 | public void onResp(BaseResp baseResp) { 921 | WritableMap map = Arguments.createMap(); 922 | map.putInt("errCode", baseResp.errCode); 923 | map.putString("errStr", baseResp.errStr); 924 | map.putString("openId", baseResp.openId); 925 | map.putString("transaction", baseResp.transaction); 926 | 927 | if (baseResp instanceof SendAuth.Resp) { 928 | SendAuth.Resp resp = (SendAuth.Resp) (baseResp); 929 | 930 | map.putString("type", "SendAuth.Resp"); 931 | map.putString("code", resp.code); 932 | map.putString("state", resp.state); 933 | map.putString("url", resp.url); 934 | map.putString("lang", resp.lang); 935 | map.putString("country", resp.country); 936 | } else if (baseResp instanceof SendMessageToWX.Resp) { 937 | SendMessageToWX.Resp resp = (SendMessageToWX.Resp) (baseResp); 938 | map.putString("type", "SendMessageToWX.Resp"); 939 | } else if (baseResp instanceof PayResp) { 940 | PayResp resp = (PayResp) (baseResp); 941 | map.putString("type", "PayReq.Resp"); 942 | map.putString("returnKey", resp.returnKey); 943 | } else if (baseResp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) { 944 | WXLaunchMiniProgram.Resp resp = (WXLaunchMiniProgram.Resp) baseResp; 945 | // 对应JsApi navigateBackApplication中的extraData字段数据 946 | String extraData = resp.extMsg; 947 | map.putString("type", "WXLaunchMiniProgramReq.Resp"); 948 | map.putString("extraData", extraData); 949 | map.putString("extMsg", extraData); 950 | } else if (baseResp instanceof WXOpenCustomerServiceChat.Resp) { 951 | WXOpenCustomerServiceChat.Resp resp = (WXOpenCustomerServiceChat.Resp) (baseResp); 952 | map.putString("type", "WXOpenCustomerServiceReq.Resp"); 953 | } 954 | 955 | this.getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("WeChat_Resp", map); 956 | 957 | // 未处理过handleLaunchAppReq,不做清除缓存 958 | if (hasHandleLaunch) { 959 | cacheLaunchIntent = null; 960 | } 961 | } 962 | 963 | private interface ImageCallback { 964 | void invoke(@Nullable Bitmap bitmap); 965 | } 966 | 967 | private interface MediaObjectCallback { 968 | void invoke(@Nullable WXMediaMessage.IMediaObject mediaObject); 969 | } 970 | 971 | } 972 | --------------------------------------------------------------------------------