diff --git a/README.md b/README.md index 3e250ef..af46107 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,64 @@ -# @uiw/react-native-wechat +@uiw/react-native-wechat +----- -## Getting started +React Native 包使用微信分享、登录、收藏、支付等功能。 -`$ npm install @uiw/react-native-wechat --save` +## 注意事项 -### Mostly automatic installation +
+iOS: 微信授权登录 Universal Link(通用链接) -`$ react-native link @uiw/react-native-wechat` +> Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。 +> 看起来就是一条普通的 https 链接,当然是我们在该链接域名根目录配置过的一个链接,也可以在该链接中放置对应的H5页面。当用户的点击该链接,只要手机中安装了支持该链接的 APP 就会直接进入到 APP 中。如果没有安装APP则会跳转到 Safari 浏览器中,展示 H5 页面。对用户来说则是一个无缝跳转的过程。 -## Usage -```javascript -import RNWechat from '@uiw/react-native-wechat'; +创建一个名为 `apple-app-site-association` 的文件,如下: -// TODO: What to do with the module? -RNWechat; +```json +{ + "applinks": { + "apps": [], + "details": [ + { + "appID": "Team ID.com.uiwjs.XXX", + "paths": ["/uiwjs/*"] + }, + { + "appID": "Team ID.com.uiwjs.XXX", + "paths": ["/uiwjstest/*"] + } + ] + } +} ``` +上传该文件到你的域名所对应的`根目录`或`xxx目录`下,`apple-app-site-association` 文件不需要扩展名。 + +**注意:** 苹果提供了一个[网页来验证](https://search.developer.apple.com/appsearch-validation-tool/)我们编写的这个 [apple-app-site-association](https://search.developer.apple.com/appsearch-validation-tool/) 是否合法有效。 + +``` +根目录 +https://uiwjs.github.io/apple-app-site-association + +xxx目录 +https://uiwjs.github.io/react-native-wechat/apple-app-site-association +``` + +
+ +## 安装依赖 + +```bash +yarn add @uiw/react-native-alipay +# react-native version >= 0.60+ +$ cd ios && pod install +``` + +## 使用 + +```js +import Wechat from '@uiw/react-native-wechat'; + +``` ## 开发 @@ -37,4 +80,6 @@ npx create-react-native-module --package-identifier com.uiwjs.react.wechat --obj ## 相关连接 -- [微信(SDK):iOS定位SDK v1.8.7.1](https://developers.weixin.qq.com/doc/oplatform/Downloads/iOS_Resource.html) +- [微信(SDK):iOS SDK v1.8.7.1](https://developers.weixin.qq.com/doc/oplatform/Downloads/iOS_Resource.html) +- [微信(SDK):iOS 接入指南](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) +- [@uiw/react-native-alipay](https://github.com/uiwjs/react-native-alipay) 支付宝支付。 diff --git a/example/App.js b/example/App.js index 56115f3..cf07815 100644 --- a/example/App.js +++ b/example/App.js @@ -9,30 +9,28 @@ */ import React, { Component } from 'react'; -import { Platform, StyleSheet, Text, View } from 'react-native'; +import { Platform, SafeAreaView, StyleSheet, Text, View } from 'react-native'; import RNWechat from '@uiw/react-native-wechat'; -export default class App extends Component<{}> { +export default class App extends Component { state = { - status: 'starting', message: '--' }; componentDidMount() { - RNWechat.sampleMethod('Testing', 123, (message) => { - this.setState({ - status: 'native callback received', - message - }); - }); + // RNWechat.sampleMethod('Testing', 123, (message) => { + // this.setState({ + // message + // }); + // }); } render() { return ( - - ☆RNWechat example☆ - STATUS: {this.state.status} - ☆NATIVE CALLBACK MESSAGE☆ - {this.state.message} - + + + ☆Wechat Example☆ + {this.state.message} + + ); } } @@ -40,7 +38,7 @@ export default class App extends Component<{}> { const styles = StyleSheet.create({ container: { flex: 1, - justifyContent: 'center', + // justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, diff --git a/example/apple-app-site-association b/example/apple-app-site-association new file mode 100644 index 0000000..373fef5 --- /dev/null +++ b/example/apple-app-site-association @@ -0,0 +1,11 @@ +{ + "applinks": { + "apps": [], + "details": [ + { + "appID": "Team ID.com.uiwjs.XXX", + "paths": ["/react-native-wechat/*"] + } + ] + } +} \ No newline at end of file diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 83a2057..3e708c3 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -67,6 +67,7 @@ PODS: - DoubleConversion - glog - glog (0.3.5) + - libWeChatSDK (1.7.5) - OpenSSL-Universal (1.0.2.19): - OpenSSL-Universal/Static (= 1.0.2.19) - OpenSSL-Universal/Static (1.0.2.19) @@ -296,6 +297,9 @@ PODS: - React-Core (= 0.63.2) - React-cxxreact (= 0.63.2) - React-jsi (= 0.63.2) + - RNWechat (1.0.0): + - libWeChatSDK + - React - Yoga (1.14.0) - YogaKit (1.18.1): - Yoga (~> 1.14) @@ -347,6 +351,7 @@ DEPENDENCIES: - React-RCTText (from `../node_modules/react-native/Libraries/Text`) - React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`) - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) + - RNWechat (from `../../ios`) - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) SPEC REPOS: @@ -361,6 +366,7 @@ SPEC REPOS: - Flipper-PeerTalk - Flipper-RSocket - FlipperKit + - libWeChatSDK - OpenSSL-Universal - YogaKit @@ -415,6 +421,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/Libraries/Vibration" ReactCommon: :path: "../node_modules/react-native/ReactCommon" + RNWechat: + :path: "../../ios" Yoga: :path: "../node_modules/react-native/ReactCommon/yoga" @@ -434,6 +442,7 @@ SPEC CHECKSUMS: FlipperKit: bc68102cd4952a258a23c9c1b316c7bec1fecf83 Folly: b73c3869541e86821df3c387eb0af5f65addfab4 glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3 + libWeChatSDK: e34a813bccc704856a33943bde8279be4e4c82a0 OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355 RCTRequired: f13f25e7b12f925f1f6a6a8c69d929a03c0129fe RCTTypeSafety: 44982c5c8e43ff4141eb519a8ddc88059acd1f3a @@ -455,6 +464,7 @@ SPEC CHECKSUMS: React-RCTText: 1b6773e776e4b33f90468c20fe3b16ca3e224bb8 React-RCTVibration: 4d2e726957f4087449739b595f107c0d4b6c2d2d ReactCommon: a0a1edbebcac5e91338371b72ffc66aa822792ce + RNWechat: 13905ec89041c708f753131d23edb6543de8d5ed Yoga: 7740b94929bbacbddda59bf115b5317e9a161598 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/example/ios/example.xcodeproj/project.pbxproj b/example/ios/example.xcodeproj/project.pbxproj index e7ba4ce..e4b90f8 100644 --- a/example/ios/example.xcodeproj/project.pbxproj +++ b/example/ios/example.xcodeproj/project.pbxproj @@ -15,11 +15,11 @@ 2D02E4BD1E0B4A84006451C7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 2DCD954D1E0B4F2C00145EB5 /* exampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* exampleTests.m */; }; - 570DD08EC1B88C09BD911FB2 /* libPods-example-exampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 75D43CC657AE13EB606A88D4 /* libPods-example-exampleTests.a */; }; + 6B217C1722AD96B734E11E28 /* libPods-example-tvOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B5F8D9208E30CB59FFD9DF61 /* libPods-example-tvOSTests.a */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; - 9449D8E870EEEA1280983069 /* libPods-example-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FF72D1ED3398B315E1A611C6 /* libPods-example-tvOS.a */; }; - AD33AD02DAD3C931A3561457 /* libPods-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DE688222BA941BA9019FB103 /* libPods-example.a */; }; - C2D7620BFB1AD632BBF021E2 /* libPods-example-tvOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B14C59F113B17643C1599005 /* libPods-example-tvOSTests.a */; }; + 9747F223637EC163F094ABF9 /* libPods-example-exampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D5A635247E39CCAE77566DE0 /* libPods-example-exampleTests.a */; }; + A08173214D51EF1A0B5A4E62 /* libPods-example-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C71C447D57E01310FAEBF806 /* libPods-example-tvOS.a */; }; + F3BB9D73AD01B842D5B8D5F3 /* libPods-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BEF8386A17C5C5007A3B7DE1 /* libPods-example.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -44,6 +44,7 @@ 00E356EE1AD99517003FC87E /* exampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = exampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 00E356F21AD99517003FC87E /* exampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = exampleTests.m; sourceTree = ""; }; + 07391488E94D88F163C4FF4B /* Pods-example-exampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.release.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.release.xcconfig"; sourceTree = ""; }; 13B07F961A680F5B00A75B9A /* example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = example/AppDelegate.h; sourceTree = ""; }; 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = example/AppDelegate.m; sourceTree = ""; }; @@ -52,21 +53,20 @@ 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = example/main.m; sourceTree = ""; }; 2D02E47B1E0B4A5D006451C7 /* example-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "example-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 2D02E4901E0B4A5D006451C7 /* example-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "example-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 71108372967D2DF7DCD99BCF /* Pods-example-tvOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOSTests.release.xcconfig"; path = "Target Support Files/Pods-example-tvOSTests/Pods-example-tvOSTests.release.xcconfig"; sourceTree = ""; }; - 75D43CC657AE13EB606A88D4 /* libPods-example-exampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-exampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 31516949793D0C7216BC4C4A /* Pods-example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.release.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.release.xcconfig"; sourceTree = ""; }; + 421916570979510F95B19F08 /* Pods-example-tvOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOSTests.release.xcconfig"; path = "Target Support Files/Pods-example-tvOSTests/Pods-example-tvOSTests.release.xcconfig"; sourceTree = ""; }; 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = example/LaunchScreen.storyboard; sourceTree = ""; }; - 8AD4667EA129381D1AA1195B /* Pods-example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.debug.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.debug.xcconfig"; sourceTree = ""; }; - 909AA4FF29607443046F3676 /* Pods-example-tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOS.release.xcconfig"; path = "Target Support Files/Pods-example-tvOS/Pods-example-tvOS.release.xcconfig"; sourceTree = ""; }; - B14C59F113B17643C1599005 /* libPods-example-tvOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-tvOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - BBD565EB9C7A9497A48ECDEA /* Pods-example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.release.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.release.xcconfig"; sourceTree = ""; }; - C22BDD7188B56A02D6C7EA3E /* Pods-example-exampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.release.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.release.xcconfig"; sourceTree = ""; }; - DE688222BA941BA9019FB103 /* libPods-example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - E1ECC7F9ED2360AD27D88048 /* Pods-example-tvOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOSTests.debug.xcconfig"; path = "Target Support Files/Pods-example-tvOSTests/Pods-example-tvOSTests.debug.xcconfig"; sourceTree = ""; }; + 8ADF1087B43A26911F720B75 /* Pods-example-tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOS.release.xcconfig"; path = "Target Support Files/Pods-example-tvOS/Pods-example-tvOS.release.xcconfig"; sourceTree = ""; }; + 9FC35016822D626703B8DAA6 /* Pods-example-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-example-tvOS/Pods-example-tvOS.debug.xcconfig"; sourceTree = ""; }; + A06ED8C449E3482A4B99BA60 /* Pods-example-exampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.debug.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.debug.xcconfig"; sourceTree = ""; }; + B5F8D9208E30CB59FFD9DF61 /* libPods-example-tvOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-tvOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + BEF8386A17C5C5007A3B7DE1 /* libPods-example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + C71C447D57E01310FAEBF806 /* libPods-example-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + CF836C8C8F54BB605C2EF58D /* Pods-example-tvOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOSTests.debug.xcconfig"; path = "Target Support Files/Pods-example-tvOSTests/Pods-example-tvOSTests.debug.xcconfig"; sourceTree = ""; }; + D5A635247E39CCAE77566DE0 /* libPods-example-exampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-exampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; }; - F978DB4F2AF6C26CBA8E2BB5 /* Pods-example-exampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.debug.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.debug.xcconfig"; sourceTree = ""; }; - F9805635668EB65D5CB9BEA4 /* Pods-example-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-example-tvOS/Pods-example-tvOS.debug.xcconfig"; sourceTree = ""; }; - FF72D1ED3398B315E1A611C6 /* libPods-example-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + F8613EAC78D636C8C5C4678D /* Pods-example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.debug.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -74,7 +74,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 570DD08EC1B88C09BD911FB2 /* libPods-example-exampleTests.a in Frameworks */, + 9747F223637EC163F094ABF9 /* libPods-example-exampleTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -82,7 +82,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - AD33AD02DAD3C931A3561457 /* libPods-example.a in Frameworks */, + F3BB9D73AD01B842D5B8D5F3 /* libPods-example.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -90,7 +90,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9449D8E870EEEA1280983069 /* libPods-example-tvOS.a in Frameworks */, + A08173214D51EF1A0B5A4E62 /* libPods-example-tvOS.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -98,7 +98,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - C2D7620BFB1AD632BBF021E2 /* libPods-example-tvOSTests.a in Frameworks */, + 6B217C1722AD96B734E11E28 /* libPods-example-tvOSTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -141,10 +141,10 @@ children = ( ED297162215061F000B7C4FE /* JavaScriptCore.framework */, ED2971642150620600B7C4FE /* JavaScriptCore.framework */, - DE688222BA941BA9019FB103 /* libPods-example.a */, - 75D43CC657AE13EB606A88D4 /* libPods-example-exampleTests.a */, - FF72D1ED3398B315E1A611C6 /* libPods-example-tvOS.a */, - B14C59F113B17643C1599005 /* libPods-example-tvOSTests.a */, + BEF8386A17C5C5007A3B7DE1 /* libPods-example.a */, + D5A635247E39CCAE77566DE0 /* libPods-example-exampleTests.a */, + C71C447D57E01310FAEBF806 /* libPods-example-tvOS.a */, + B5F8D9208E30CB59FFD9DF61 /* libPods-example-tvOSTests.a */, ); name = Frameworks; sourceTree = ""; @@ -185,16 +185,15 @@ E47C9E60A31BAC49C345EBB5 /* Pods */ = { isa = PBXGroup; children = ( - 8AD4667EA129381D1AA1195B /* Pods-example.debug.xcconfig */, - BBD565EB9C7A9497A48ECDEA /* Pods-example.release.xcconfig */, - F978DB4F2AF6C26CBA8E2BB5 /* Pods-example-exampleTests.debug.xcconfig */, - C22BDD7188B56A02D6C7EA3E /* Pods-example-exampleTests.release.xcconfig */, - F9805635668EB65D5CB9BEA4 /* Pods-example-tvOS.debug.xcconfig */, - 909AA4FF29607443046F3676 /* Pods-example-tvOS.release.xcconfig */, - E1ECC7F9ED2360AD27D88048 /* Pods-example-tvOSTests.debug.xcconfig */, - 71108372967D2DF7DCD99BCF /* Pods-example-tvOSTests.release.xcconfig */, + F8613EAC78D636C8C5C4678D /* Pods-example.debug.xcconfig */, + 31516949793D0C7216BC4C4A /* Pods-example.release.xcconfig */, + A06ED8C449E3482A4B99BA60 /* Pods-example-exampleTests.debug.xcconfig */, + 07391488E94D88F163C4FF4B /* Pods-example-exampleTests.release.xcconfig */, + 9FC35016822D626703B8DAA6 /* Pods-example-tvOS.debug.xcconfig */, + 8ADF1087B43A26911F720B75 /* Pods-example-tvOS.release.xcconfig */, + CF836C8C8F54BB605C2EF58D /* Pods-example-tvOSTests.debug.xcconfig */, + 421916570979510F95B19F08 /* Pods-example-tvOSTests.release.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -205,11 +204,11 @@ isa = PBXNativeTarget; buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "exampleTests" */; buildPhases = ( - 582B0F546BB239DB9DF92707 /* [CP] Check Pods Manifest.lock */, + 45C5DD83A5C85AA81826A4D0 /* [CP] Check Pods Manifest.lock */, 00E356EA1AD99517003FC87E /* Sources */, 00E356EB1AD99517003FC87E /* Frameworks */, 00E356EC1AD99517003FC87E /* Resources */, - DA34E751E2C71F57C552EAC5 /* [CP] Copy Pods Resources */, + 0871D63CA29DD2644DABBDA5 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -225,13 +224,13 @@ isa = PBXNativeTarget; buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "example" */; buildPhases = ( - 98E0760BA032B1603841008A /* [CP] Check Pods Manifest.lock */, + B6E4003A8D62BF1A679DAFDB /* [CP] Check Pods Manifest.lock */, FD10A7F022414F080027D42C /* Start Packager */, 13B07F871A680F5B00A75B9A /* Sources */, 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, - 66F08A9D6CCB1B1B39C3B45F /* [CP] Copy Pods Resources */, + 2A8CE86D1E0E0A3DAE45876D /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -246,7 +245,7 @@ isa = PBXNativeTarget; buildConfigurationList = 2D02E4BA1E0B4A5E006451C7 /* Build configuration list for PBXNativeTarget "example-tvOS" */; buildPhases = ( - AFE2BF543DEFF70A7C2A3D9B /* [CP] Check Pods Manifest.lock */, + DC1F1E1B1FEDE08D9D93DCB0 /* [CP] Check Pods Manifest.lock */, FD10A7F122414F3F0027D42C /* Start Packager */, 2D02E4771E0B4A5D006451C7 /* Sources */, 2D02E4781E0B4A5D006451C7 /* Frameworks */, @@ -266,7 +265,7 @@ isa = PBXNativeTarget; buildConfigurationList = 2D02E4BB1E0B4A5E006451C7 /* Build configuration list for PBXNativeTarget "example-tvOSTests" */; buildPhases = ( - 6134E0AE72C1AE4344E462C7 /* [CP] Check Pods Manifest.lock */, + 7E03A9B2326111C7167146CA /* [CP] Check Pods Manifest.lock */, 2D02E48C1E0B4A5D006451C7 /* Sources */, 2D02E48D1E0B4A5D006451C7 /* Frameworks */, 2D02E48E1E0B4A5D006451C7 /* Resources */, @@ -294,6 +293,7 @@ TestTargetID = 13B07F861A680F5B00A75B9A; }; 13B07F861A680F5B00A75B9A = { + DevelopmentTeam = 968DSZ49MT; LastSwiftMigration = 1120; }; 2D02E47A1E0B4A5D006451C7 = { @@ -377,6 +377,42 @@ shellPath = /bin/sh; shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; }; + 0871D63CA29DD2644DABBDA5 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources.sh", + "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 2A8CE86D1E0E0A3DAE45876D /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources.sh", + "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; 2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -391,7 +427,7 @@ shellPath = /bin/sh; shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; }; - 582B0F546BB239DB9DF92707 /* [CP] Check Pods Manifest.lock */ = { + 45C5DD83A5C85AA81826A4D0 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -413,7 +449,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 6134E0AE72C1AE4344E462C7 /* [CP] Check Pods Manifest.lock */ = { + 7E03A9B2326111C7167146CA /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -435,25 +471,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 66F08A9D6CCB1B1B39C3B45F /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 98E0760BA032B1603841008A /* [CP] Check Pods Manifest.lock */ = { + B6E4003A8D62BF1A679DAFDB /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -475,7 +493,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - AFE2BF543DEFF70A7C2A3D9B /* [CP] Check Pods Manifest.lock */ = { + DC1F1E1B1FEDE08D9D93DCB0 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -497,24 +515,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - DA34E751E2C71F57C552EAC5 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; FD10A7F022414F080027D42C /* Start Packager */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -608,7 +608,7 @@ /* Begin XCBuildConfiguration section */ 00E356F61AD99517003FC87E /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = F978DB4F2AF6C26CBA8E2BB5 /* Pods-example-exampleTests.debug.xcconfig */; + baseConfigurationReference = A06ED8C449E3482A4B99BA60 /* Pods-example-exampleTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -631,7 +631,7 @@ }; 00E356F71AD99517003FC87E /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = C22BDD7188B56A02D6C7EA3E /* Pods-example-exampleTests.release.xcconfig */; + baseConfigurationReference = 07391488E94D88F163C4FF4B /* Pods-example-exampleTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; @@ -651,11 +651,12 @@ }; 13B07F941A680F5B00A75B9A /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 8AD4667EA129381D1AA1195B /* Pods-example.debug.xcconfig */; + baseConfigurationReference = F8613EAC78D636C8C5C4678D /* Pods-example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 968DSZ49MT; ENABLE_BITCODE = NO; INFOPLIST_FILE = example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -664,7 +665,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = com.uiwjs.react.example.wechat; PRODUCT_NAME = example; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -674,11 +675,12 @@ }; 13B07F951A680F5B00A75B9A /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BBD565EB9C7A9497A48ECDEA /* Pods-example.release.xcconfig */; + baseConfigurationReference = 31516949793D0C7216BC4C4A /* Pods-example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 968DSZ49MT; INFOPLIST_FILE = example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( @@ -686,7 +688,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = com.uiwjs.react.example.wechat; PRODUCT_NAME = example; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -695,7 +697,7 @@ }; 2D02E4971E0B4A5E006451C7 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = F9805635668EB65D5CB9BEA4 /* Pods-example-tvOS.debug.xcconfig */; + baseConfigurationReference = 9FC35016822D626703B8DAA6 /* Pods-example-tvOS.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; @@ -723,7 +725,7 @@ }; 2D02E4981E0B4A5E006451C7 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 909AA4FF29607443046F3676 /* Pods-example-tvOS.release.xcconfig */; + baseConfigurationReference = 8ADF1087B43A26911F720B75 /* Pods-example-tvOS.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; @@ -751,7 +753,7 @@ }; 2D02E4991E0B4A5E006451C7 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = E1ECC7F9ED2360AD27D88048 /* Pods-example-tvOSTests.debug.xcconfig */; + baseConfigurationReference = CF836C8C8F54BB605C2EF58D /* Pods-example-tvOSTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; @@ -778,7 +780,7 @@ }; 2D02E49A1E0B4A5E006451C7 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 71108372967D2DF7DCD99BCF /* Pods-example-tvOSTests.release.xcconfig */; + baseConfigurationReference = 421916570979510F95B19F08 /* Pods-example-tvOSTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; diff --git a/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/example/yarn.lock b/example/yarn.lock index 8460a5b..a7a444d 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -1291,14 +1291,14 @@ semver "^7.3.2" tsutils "^3.17.1" -"@uiw/react-native-wechat@link:../": +"@uiw/react-native-wechat@link:..": version "0.0.0" uid "" abab@^2.0.0: - version "2.0.3" - resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.3.tgz#623e2075e02eb2d3f2475e49f99c91846467907a" - integrity sha512-tsFzPpcttalNjFBCFMqsKYQcWxxen1pgJR56by//QwvJc4/OUS3kPOOttx2tSIfjsylB0pYu7f5D3K1RCxUnUg== + version "2.0.4" + resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.4.tgz#6dfa57b417ca06d21b2478f0e638302f99c2405c" + integrity sha512-Eu9ELJWCz/c1e9gTiCY+FceWxcqzjYEbqMgtndnuSqZSUCOL73TWNK2mHfIj4Cw2E/ongOp+JISVNCmovt2KYQ== abort-controller@^3.0.0: version "3.0.0" diff --git a/index.d.ts b/index.d.ts index e69de29..af62c63 100644 --- a/index.d.ts +++ b/index.d.ts @@ -0,0 +1,7 @@ + +/** + * 向微信注册应用 + * @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/) + * @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。 + */ +export function registerApp(appid: string, universalLink: string): void; \ No newline at end of file diff --git a/index.js b/index.js index beb9fea..a6345f6 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,14 @@ import { NativeModules } from 'react-native'; -const { RNWechat } = NativeModules; +// const { RNWechat } = NativeModules; -export default RNWechat; +export default class Wechat { + /** + * 向微信注册应用 + * @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/) + * @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。 + */ + static registerApp(appid, universalLink) { + return NativeModules.RNAMapGeolocation.registerApp(appid, universalLink); + } +} diff --git a/ios/RNWechat.h b/ios/RNWechat.h index 09a7219..fa87aa1 100644 --- a/ios/RNWechat.h +++ b/ios/RNWechat.h @@ -1,5 +1,7 @@ #import +#import "WXApi.h" +#import "WXApiObject.h" -@interface RNWechat : NSObject +@interface RNWechat : NSObject @end diff --git a/ios/RNWechat.m b/ios/RNWechat.m index f1102ae..9c13504 100644 --- a/ios/RNWechat.m +++ b/ios/RNWechat.m @@ -1,13 +1,55 @@ #import "RNWechat.h" -@implementation RNWechat +// Define error messages +#define INVOKE_FAILED (@"WeChat API invoke returns false.") + +@implementation RNWechat { + BOOL *_api; +} RCT_EXPORT_MODULE() +- (instancetype)init { + self = [super init]; + if (self) { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil]; + } + return self; +} -RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback) +- (void)dealloc { - // TODO: Implement some actually useful functionality - callback(@[[NSString stringWithFormat: @"numberArgument: %@ stringArgument: %@", numberArgument, stringArgument]]); + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (BOOL)handleOpenURL:(NSNotification *)aNotification +{ + NSString * aURLString = [aNotification userInfo][@"url"]; + NSURL * aURL = [NSURL URLWithString:aURLString]; + + if ([WXApi handleOpenURL:aURL delegate:self]) + { + return YES; + } else { + return NO; + } +} + +- (dispatch_queue_t)methodQueue +{ + return dispatch_get_main_queue(); +} + ++ (BOOL)requiresMainQueueSetup { + return YES; +} + +// 注册 appid +RCT_REMAP_METHOD(registerApp, resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { + if ([WXApi registerApp:@"wxd930ea5d5a258f4f" universalLink:@"wxd930ea5d5a258f4f"]) { + resolve(@[[NSNull null]]); + } else { + reject(@"-10404", INVOKE_FAILED, nil); + } } @end diff --git a/ios/RNWechat.podspec b/ios/RNWechat.podspec index 33620f6..48c5f48 100644 --- a/ios/RNWechat.podspec +++ b/ios/RNWechat.podspec @@ -1,27 +1,32 @@ require "json" -package = JSON.parse(File.read(File.join(__dir__, "package.json"))) +package = JSON.parse(File.read(File.join(__dir__, "..", "package.json"))) Pod::Spec.new do |s| s.name = "RNWechat" s.version = package["version"] s.summary = package["description"] s.description = <<-DESC - @uiw/react-native-wechat + React Native 包使用微信分享、登录、收藏、支付等功能。 DESC s.homepage = "https://github.com/uiwjs/react-native-wechat" # brief license entry: - s.license = "MIT" + # s.license = "MIT" # optional - use expanded license entry instead: # s.license = { :type => "MIT", :file => "LICENSE" } - s.authors = { "Kenny Wong" => "wowohoo@qq.com" } + s.license = package["license"] + s.author = { package["author"]["name"] => package["author"]["email"] } s.platforms = { :ios => "9.0" } s.source = { :git => "https://github.com/uiwjs/react-native-wechat.git", :tag => "#{s.version}" } - s.source_files = "ios/**/*.{h,c,m,swift}" + s.source_files = "**/*.{h,c,m,swift}" s.requires_arc = true + # s.static_framework = true s.dependency "React" + s.dependency "libWeChatSDK" + # s.vendored_library "libWeChatSDK" + # s.library = "c++", "z" # ... # s.dependency "..." end diff --git a/ios/RNWechat.xcodeproj/project.pbxproj b/ios/RNWechat.xcodeproj/project.pbxproj index 55c270b..f046a8b 100644 --- a/ios/RNWechat.xcodeproj/project.pbxproj +++ b/ios/RNWechat.xcodeproj/project.pbxproj @@ -6,6 +6,10 @@ objectVersion = 46; objects = { +/* Begin PBXBuildFile section */ + B9CCD3AF24D41B010084C62F /* libWeChatSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B9CCD3AE24D41B000084C62F /* libWeChatSDK.a */; }; +/* End PBXBuildFile section */ + /* Begin PBXCopyFilesBuildPhase section */ 58B511D91A9E6C8500147676 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; @@ -20,6 +24,7 @@ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libRNWechat.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNWechat.a; sourceTree = BUILT_PRODUCTS_DIR; }; + B9CCD3AE24D41B000084C62F /* libWeChatSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWeChatSDK.a; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -27,6 +32,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + B9CCD3AF24D41B010084C62F /* libWeChatSDK.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -45,9 +51,18 @@ isa = PBXGroup; children = ( 134814211AA4EA7D00B7C361 /* Products */, + B9CCD3AD24D41B000084C62F /* Frameworks */, ); sourceTree = ""; }; + B9CCD3AD24D41B000084C62F /* Frameworks */ = { + isa = PBXGroup; + children = ( + B9CCD3AE24D41B000084C62F /* libWeChatSDK.a */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -166,6 +181,10 @@ ); MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); SDKROOT = iphoneos; }; name = Debug; @@ -217,6 +236,10 @@ "\"$(inherited)\"", ); MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -231,8 +254,14 @@ "$(SRCROOT)/../../../React/**", "$(SRCROOT)/../../react-native/React/**", ); - LIBRARY_SEARCH_PATHS = "$(inherited)"; - OTHER_LDFLAGS = "-ObjC"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)", + ); + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); PRODUCT_NAME = RNWechat; SKIP_INSTALL = YES; }; @@ -247,8 +276,14 @@ "$(SRCROOT)/../../../React/**", "$(SRCROOT)/../../react-native/React/**", ); - LIBRARY_SEARCH_PATHS = "$(inherited)"; - OTHER_LDFLAGS = "-ObjC"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)", + ); + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); PRODUCT_NAME = RNWechat; SKIP_INSTALL = YES; }; diff --git a/ios/RNWechat.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ios/RNWechat.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/ios/RNWechat.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/WXApi.h b/ios/WXApi.h new file mode 100644 index 0000000..c5ca13f --- /dev/null +++ b/ios/WXApi.h @@ -0,0 +1,198 @@ +// +// WXApi.h +// 所有Api接口 +// +// Created by Wechat on 12-2-28. +// Copyright (c) 2012年 Tencent. All rights reserved. +// + +#import +#import "WXApiObject.h" + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark - WXApiDelegate +/*! @brief 接收并处理来自微信终端程序的事件消息 + * + * 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。 + * WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。 + */ +@protocol WXApiDelegate +@optional + +/*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果 + * + * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 + * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 + * @param req 具体请求内容,是自动释放的 + */ +- (void)onReq:(BaseReq*)req; + + + +/*! @brief 发送一个sendReq后,收到微信的回应 + * + * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 + * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 + * @param resp具体的回应内容,是自动释放的 + */ +- (void)onResp:(BaseResp*)resp; + +@end + +#pragma mark - WXApiLogDelegate + +@protocol WXApiLogDelegate + +- (void)onLog:(NSString*)log logLevel:(WXLogLevel)level; + +@end + + +#pragma mark - WXApi + +/*! @brief 微信Api接口函数类 + * + * 该类封装了微信终端SDK的所有接口 + */ +@interface WXApi : NSObject + +/*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 + * + * 需要在每次启动第三方应用程序时调用。 + * @attention 请保证在主线程中调用此函数 + * @param appid 微信开发者ID + * @param universalLink 微信开发者Universal Link + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink; + + +/*! @brief 处理旧版微信通过URL启动App时传递的数据 + * + * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 + * @param url 微信启动第三方应用时传递过来的URL + * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)handleOpenURL:(NSURL *)url delegate:(nullable id)delegate; + + +/*! @brief 处理微信通过Universal Link启动App时传递的数据 + * + * 需要在 application:continueUserActivity:restorationHandler:中调用。 + * @param userActivity 微信启动第三方应用时系统API传递过来的userActivity + * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)handleOpenUniversalLink:(NSUserActivity *)userActivity delegate:(nullable id)delegate; + + +/*! @brief 检查微信是否已被用户安装 + * + * @return 微信已安装返回YES,未安装返回NO。 + */ ++ (BOOL)isWXAppInstalled; + + + +/*! @brief 判断当前微信的版本是否支持OpenApi + * + * @return 支持返回YES,不支持返回NO。 + */ ++ (BOOL)isWXAppSupportApi; + + + +/*! @brief 获取微信的itunes安装地址 + * + * @return 微信的安装地址字符串。 + */ ++ (NSString *)getWXAppInstallUrl; + + + +/*! @brief 获取当前微信SDK的版本号 + * + * @return 返回当前微信SDK的版本号 + */ ++ (NSString *)getApiVersion; + + + +/*! @brief 打开微信 + * + * @return 成功返回YES,失败返回NO。 + */ ++ (BOOL)openWXApp; + + + +/*! @brief 发送请求到微信,等待微信返回onResp + * + * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型 + * SendAuthReq、SendMessageToWXReq、PayReq等。 + * @param req 具体的发送请求。 + * @param completion 调用结果回调block + */ ++ (void)sendReq:(BaseReq *)req completion:(void (^ __nullable)(BOOL success))completion; + +/*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面 + * + * 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有 + * GetMessageFromWXResp、ShowMessageFromWXResp等。 + * @param resp 具体的应答内容 + * @param completion 调用结果回调block + */ ++ (void)sendResp:(BaseResp*)resp completion:(void (^ __nullable)(BOOL success))completion; + + +/*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp + * + * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。 + * @param req 具体的发送请求。 + * @param viewController 当前界面对象。 + * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 + * @param completion 调用结果回调block + */ ++ (void)sendAuthReq:(SendAuthReq *)req viewController:(UIViewController*)viewController delegate:(nullable id)delegate completion:(void (^ __nullable)(BOOL success))completion; + + +/*! @brief 测试函数,用于排查当前App通过Universal Link方式分享到微信的流程 + 注意1: 调用自检函数之前必须要先调用registerApp:universalLink接口, 并确认调用成功 + 注意2: 自检过程中会有Log产生,可以先调用startLogByLevel函数,根据Log排查问题 + 注意3: 会多次回调block + 注意4: 仅用于新接入SDK时调试使用,请勿在正式环境的调用 + * + * 当completion回调的step为WXULCheckStepFinal时,表示检测通过,Universal Link接入成功 + * @param completion 回调Block + */ ++ (void)checkUniversalLinkReady:(nonnull WXCheckULCompletion)completion; + + +/*! @brief WXApi的成员函数,接受微信的log信息。byBlock + 注意1:SDK会强引用这个block,注意不要导致内存泄漏,注意不要导致内存泄漏 + 注意2:调用过一次startLog by block之后,如果再调用一次任意方式的startLoad,会释放上一次logBlock,不再回调上一个logBlock + * + * @param level 打印log的级别 + * @param logBlock 打印log的回调block + */ + ++ (void)startLogByLevel:(WXLogLevel)level logBlock:(WXLogBolock)logBlock; + +/*! @brief WXApi的成员函数,接受微信的log信息。byDelegate + 注意1:sdk会弱引用这个delegate,这里可加任意对象为代理,不需要与WXApiDelegate同一个对象 + 注意2:调用过一次startLog by delegate之后,再调用一次任意方式的startLoad,不会再回调上一个logDelegate对象 + * @param level 打印log的级别 + * @param logDelegate 打印log的回调代理, + */ ++ (void)startLogByLevel:(WXLogLevel)level logDelegate:(id)logDelegate; + +/*! @brief 停止打印log,会清理block或者delegate为空,释放block + * @param + */ ++ (void)stopLog; + +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/WXApiObject.h b/ios/WXApiObject.h new file mode 100644 index 0000000..635dc8e --- /dev/null +++ b/ios/WXApiObject.h @@ -0,0 +1,1075 @@ +// +// MMApiObject.h +// Api对象,包含所有接口和对象数据定义 +// +// Created by Wechat on 12-2-28. +// Copyright (c) 2012年 Tencent. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/*! @brief 错误码 + * + */ +enum WXErrCode { + WXSuccess = 0, /**< 成功 */ + WXErrCodeCommon = -1, /**< 普通错误类型 */ + WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ + WXErrCodeSentFail = -3, /**< 发送失败 */ + WXErrCodeAuthDeny = -4, /**< 授权失败 */ + WXErrCodeUnsupport = -5, /**< 微信不支持 */ +}; + + + +/*! @brief 请求发送场景 + * + */ +enum WXScene { + WXSceneSession = 0, /**< 聊天界面 */ + WXSceneTimeline = 1, /**< 朋友圈 */ + WXSceneFavorite = 2, /**< 收藏 */ + WXSceneSpecifiedSession = 3, /**< 指定联系人 */ +}; + + +enum WXAPISupport { + WXAPISupportSession = 0, +}; + + + +/*! @brief 跳转profile类型 + * + */ +enum WXBizProfileType { + WXBizProfileType_Normal = 0, //**< 普通公众号 */ + WXBizProfileType_Device = 1, //**< 硬件公众号 */ +}; + +/*! @brief 分享小程序类型 + * + */ +typedef NS_ENUM(NSUInteger, WXMiniProgramType) { + WXMiniProgramTypeRelease = 0, //**< 正式版 */ + WXMiniProgramTypeTest = 1, //**< 开发版 */ + WXMiniProgramTypePreview = 2, //**< 体验版 */ +}; + +/*! @brief 跳转mp网页类型 + * + */ +enum WXMPWebviewType { + WXMPWebviewType_Ad = 0, /**< 广告网页 **/ +}; + +/*! @brief log的级别 + * + */ +typedef NS_ENUM(NSInteger,WXLogLevel) { + WXLogLevelNormal = 0, // 打印日常的日志 + WXLogLevelDetail = 1, // 打印详细的日志 +}; + + +/*! @brief 打印回调的block + * + */ +typedef void(^WXLogBolock)(NSString *log); + +/*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),检查步骤枚举值 + * + * WXULCheckStepParams 参数检测 + * WXULCheckStepSystemVersion 当前系统版本检测 + * WXULCheckStepWechatVersion 微信客户端版本检测 + * WXULCheckStepSDKInnerOperation 微信SDK内部操作检测 + * WXULCheckStepLaunchWechat App拉起微信检测 + * WXULCheckStepBackToCurrentApp 由微信返回当前App检测 + * WXULCheckStepFinal 最终结果 + */ +typedef NS_ENUM(NSInteger, WXULCheckStep) +{ + WXULCheckStepParams, + WXULCheckStepSystemVersion, + WXULCheckStepWechatVersion, + WXULCheckStepSDKInnerOperation, + WXULCheckStepLaunchWechat, + WXULCheckStepBackToCurrentApp, + WXULCheckStepFinal, +}; + + +#pragma mark - WXCheckULStepResult + +/*! @brief 该类为微信Universal Link检测函数结果类 +* +*/ +@interface WXCheckULStepResult : NSObject + +/** 是否成功 */ +@property(nonatomic, assign) BOOL success; +/** 当前错误信息 */ +@property(nonatomic, strong) NSString* errorInfo; +/** 修正建议 */ +@property(nonatomic, strong) NSString* suggestion; + +- (instancetype)initWithCheckResult:(BOOL)success errorInfo:(nullable NSString*)errorInfo suggestion:(nullable NSString*)suggestion; + +@end + + +/*! @brief 微信Universal Link检查函数 (WXApi#checkUniversalLinkReady:),回调Block + * + * @param step 当前检测步骤 + * @param result 检测结果 + */ +typedef void(^WXCheckULCompletion)(WXULCheckStep step, WXCheckULStepResult* result); + + +#pragma mark - BaseReq +/*! @brief 该类为微信终端SDK所有请求类的基类 + * + */ +@interface BaseReq : NSObject + +/** 请求类型 */ +@property (nonatomic, assign) int type; +/** 由用户微信号和AppID组成的唯一标识,需要校验微信用户是否换号登录时填写*/ +@property (nonatomic, copy) NSString *openID; + +@end + + + +#pragma mark - BaseResp +/*! @brief 该类为微信终端SDK所有响应类的基类 + * + */ +@interface BaseResp : NSObject +/** 错误码 */ +@property (nonatomic, assign) int errCode; +/** 错误提示字符串 */ +@property (nonatomic, copy) NSString *errStr; +/** 响应类型 */ +@property (nonatomic, assign) int type; + +@end + + + +#pragma mark - WXMediaMessage +@class WXMediaMessage; + +#ifndef BUILD_WITHOUT_PAY + +#pragma mark - PayReq +/*! @brief 第三方向微信终端发起支付的消息结构体 + * + * 第三方向微信终端发起支付的消息结构体,微信终端处理后会向第三方返回处理结果 + * @see PayResp + */ +@interface PayReq : BaseReq + +/** 商家向财付通申请的商家id */ +@property (nonatomic, copy) NSString *partnerId; +/** 预支付订单 */ +@property (nonatomic, copy) NSString *prepayId; +/** 随机串,防重发 */ +@property (nonatomic, copy) NSString *nonceStr; +/** 时间戳,防重发 */ +@property (nonatomic, assign) UInt32 timeStamp; +/** 商家根据财付通文档填写的数据和签名 */ +@property (nonatomic, copy) NSString *package; +/** 商家根据微信开放平台文档对数据做的签名 */ +@property (nonatomic, copy) NSString *sign; + +@end + + +#pragma mark - PayResp +/*! @brief 微信终端返回给第三方的关于支付结果的结构体 + * + * 微信终端返回给第三方的关于支付结果的结构体 + */ +@interface PayResp : BaseResp + +/** 财付通返回给商家的信息 */ +@property (nonatomic, copy) NSString *returnKey; + +@end + +#pragma mark - WXOfflinePay +/*! @brief 第三方向微信终端发起离线支付 + * + * 第三方向微信终端发起离线支付的消息结构体 + */ +@interface WXOfflinePayReq : BaseReq + +@end + +/*! @brief 第三方向微信终端发起离线支付返回 + * + * 第三方向微信终端发起离线支付返回的消息结构体 + */ +@interface WXOfflinePayResp : BaseResp + +@end + + +#pragma mark - WXNontaxPayReq +@interface WXNontaxPayReq:BaseReq + +@property (nonatomic, copy) NSString *urlString; + +@end + +#pragma mark - WXNontaxPayResp +@interface WXNontaxPayResp : BaseResp + +@property (nonatomic, copy) NSString *wxOrderId; + +@end + +#pragma mark - WXPayInsuranceReq +@interface WXPayInsuranceReq : BaseReq + +@property (nonatomic, copy) NSString *urlString; + +@end + +#pragma mark - WXPayInsuranceResp +@interface WXPayInsuranceResp : BaseResp + +@property (nonatomic, copy) NSString *wxOrderId; + +@end + +#endif + + +#pragma mark - SendAuthReq +/*! @brief 第三方程序向微信终端请求认证的消息结构 + * + * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, + * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 + * @see SendAuthResp + */ +@interface SendAuthReq : BaseReq +/** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 + * @see SendAuthResp + * @note scope字符串长度不能超过1K + */ +@property (nonatomic, copy) NSString *scope; +/** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 + * @note state字符串长度不能超过1K + */ +@property (nonatomic, copy) NSString *state; + +@end + +#pragma mark - SendAuthResp +/*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 + * + * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 + * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 + * @see onResp + */ +@interface SendAuthResp : BaseResp +@property (nonatomic, copy, nullable) NSString *code; +/** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 + * @note state字符串长度不能超过1K + */ +@property (nonatomic, copy, nullable) NSString *state; +@property (nonatomic, copy, nullable) NSString *lang; +@property (nonatomic, copy, nullable) NSString *country; +@end + + + +#pragma mark - SendMessageToWXReq +/*! @brief 第三方程序发送消息至微信终端程序的消息结构体 + * + * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, + * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 + * @see SendMessageToWXResp + */ +@interface SendMessageToWXReq : BaseReq +/** 发送消息的文本内容 + * @note 文本长度必须大于0且小于10K + */ +@property (nonatomic, copy) NSString *text; +/** 发送消息的多媒体内容 + * @see WXMediaMessage + */ +@property (nonatomic, strong) WXMediaMessage *message; +/** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ +@property (nonatomic, assign) BOOL bText; +/** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 + * @see WXScene + */ +@property (nonatomic, assign) int scene; +/** 指定发送消息的人 + * @note WXSceneSpecifiedSession时有效 + */ +@property (nonatomic, copy, nullable) NSString *toUserOpenId; +@end + +#pragma mark - SendMessageToWXResp +/*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 + * + * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 + */ +@interface SendMessageToWXResp : BaseResp +@property(nonatomic, copy) NSString *lang; +@property(nonatomic, copy) NSString *country; +@end + +#pragma mark - GetMessageFromWXReq +/*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 + * + * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, + * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 + */ +@interface GetMessageFromWXReq : BaseReq +@property (nonatomic, strong) NSString *lang; +@property (nonatomic, strong) NSString *country; +@end + + + +#pragma mark - GetMessageFromWXResp +/*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 + * + * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 + */ +@interface GetMessageFromWXResp : BaseResp +/** 向微信终端提供的文本内容 + @note 文本长度必须大于0且小于10K + */ +@property (nonatomic, strong) NSString *text; +/** 向微信终端提供的多媒体内容。 + * @see WXMediaMessage + */ +@property (nonatomic, strong) WXMediaMessage *message; +/** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ +@property (nonatomic, assign) BOOL bText; +@end + + + +#pragma mark - ShowMessageFromWXReq +/*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 + * + * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 + * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 + */ +@interface ShowMessageFromWXReq : BaseReq +/** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 + * @see WXMediaMessage + */ +@property (nonatomic, strong) WXMediaMessage *message; +@property (nonatomic, copy) NSString *lang; +@property (nonatomic, copy) NSString *country; +@end + + + +#pragma mark - ShowMessageFromWXResp +/*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 + * + * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 + * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 + */ +@interface ShowMessageFromWXResp : BaseResp +@end + + +#pragma mark - LaunchFromWXReq +/*! @brief 微信终端打开第三方程序携带的消息结构体 + * + * 微信向第三方发送的结构体,第三方不需要返回 + */ +@interface LaunchFromWXReq : BaseReq +@property (nonatomic, strong) WXMediaMessage *message; +@property (nonatomic, copy) NSString *lang; +@property (nonatomic, copy) NSString *country; +@end + + +#pragma mark - OpenWebviewReq +/* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 + * + * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 + */ +@interface OpenWebviewReq : BaseReq +/** 需要打开的网页对应的Url + * @attention 长度不能超过1024 + */ +@property(nonatomic, copy) NSString *url; + +@end + +#pragma mark - OpenWebviewResp +/*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 + * + * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 + */ +@interface OpenWebviewResp : BaseResp + +@end + + + +#pragma mark - WXOpenBusinessWebViewReq +/*! @brief 第三方通知微信启动内部浏览器,打开指定业务的网页 + * + * + */ +@interface WXOpenBusinessWebViewReq : BaseReq + +/** 网页业务类型 + * @attention + */ +@property (nonatomic, assign) UInt32 businessType; + +/** 网页业务参数 + * @attention + */ +@property (nonatomic, strong, nullable) NSDictionary *queryInfoDic; + +@end + +#pragma mark - WXOpenBusinessWebViewResp +/*! @brief 微信终端向第三方程序返回的WXOpenBusinessWebViewResp处理结果。 + * + * 第三方程序向微信终端发送WXOpenBusinessWebViewReq后,微信发送回来的处理结果,该结果用WXOpenBusinessWebViewResp表示。 + */ +@interface WXOpenBusinessWebViewResp : BaseResp +/** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 + * @attention 长度不能超过2k + */ +@property (nonatomic, copy) NSString *result; + +/** 网页业务类型 + * @attention + */ +@property (nonatomic, assign) UInt32 businessType; + +@end + + +#pragma mark - OpenRankListReq +/* ! @brief 第三方通知微信,打开硬件排行榜 + * + * 第三方通知微信,打开硬件排行榜 + */ +@interface OpenRankListReq : BaseReq + +@end + +#pragma mark - OpenRanklistResp +/*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 + * + * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 + */ +@interface OpenRankListResp : BaseResp + +@end + + +#pragma mark - WXCardItem + +@interface WXCardItem : NSObject +/** 卡id + * @attention 长度不能超过1024字节 + */ +@property (nonatomic, copy) NSString *cardId; +/** ext信息 + * @attention 长度不能超过2024字节 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; +/** + * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 + */ +@property (nonatomic, assign) UInt32 cardState; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *encryptCode; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *appID; +@end; + +#pragma mark - WXInvoiceItem + +@interface WXInvoiceItem : NSObject +/** 卡id + * @attention 长度不能超过1024字节 + */ +@property (nonatomic, copy) NSString *cardId; +/** ext信息 + * @attention 长度不能超过2024字节 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; +/** + * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 + */ +@property (nonatomic, assign) UInt32 cardState; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *encryptCode; +/** + * @attention req不需要填,chooseCard返回的。 + */ +@property (nonatomic, copy) NSString *appID; + +@end + +#pragma mark - AddCardToWXCardPackageReq +/* ! @brief 请求添加卡券至微信卡包 + * + */ + +@interface AddCardToWXCardPackageReq : BaseReq +/** 卡列表 + * @attention 个数不能超过40个 类型WXCardItem + */ +@property (nonatomic, strong) NSArray *cardAry; + +@end + + +#pragma mark - AddCardToWXCardPackageResp +/** ! @brief 微信返回第三方添加卡券结果 + * + */ + +@interface AddCardToWXCardPackageResp : BaseResp +/** 卡列表 + * @attention 个数不能超过40个 类型WXCardItem + */ +@property (nonatomic, strong) NSArray *cardAry; +@end + +#pragma mark - WXChooseCardReq +/* ! @brief 请求从微信选取卡券 + * + */ + +@interface WXChooseCardReq : BaseReq +@property (nonatomic, copy) NSString *appID; +@property (nonatomic, assign) UInt32 shopID; +@property (nonatomic, assign) UInt32 canMultiSelect; +@property (nonatomic, copy) NSString *cardType; +@property (nonatomic, copy) NSString *cardTpID; +@property (nonatomic, copy) NSString *signType; +@property (nonatomic, copy) NSString *cardSign; +@property (nonatomic, assign) UInt32 timeStamp; +@property (nonatomic, copy) NSString *nonceStr; +@end + + +#pragma mark - WXChooseCardResp +/** ! @brief 微信返回第三方请求选择卡券结果 + * + */ + +@interface WXChooseCardResp : BaseResp +@property (nonatomic, strong ) NSArray* cardAry; +@end + + +#pragma mark - WXChooseInvoiceReq +/* ! @brief 请求从微信选取发票 + * + */ +@interface WXChooseInvoiceReq : BaseReq +@property (nonatomic, copy) NSString *appID; +@property (nonatomic, assign) UInt32 shopID; +@property (nonatomic, copy) NSString *signType; +@property (nonatomic, copy) NSString *cardSign; +@property (nonatomic, assign) UInt32 timeStamp; +@property (nonatomic, copy) NSString *nonceStr; +@end + +#pragma mark - WXChooseInvoiceResp +/** ! @brief 微信返回第三方请求选择发票结果 + * + */ +@interface WXChooseInvoiceResp : BaseResp +@property (nonatomic, strong) NSArray* cardAry; +@end + +#pragma mark - WXSubscriptionReq +@interface WXSubscribeMsgReq : BaseReq +@property (nonatomic, assign) UInt32 scene; +@property (nonatomic, copy) NSString *templateId; +@property (nonatomic, copy, nullable) NSString *reserved; +@end + +#pragma mark - WXSubscriptionReq +@interface WXSubscribeMsgResp : BaseResp + +@property (nonatomic, copy) NSString *templateId; +@property (nonatomic, assign) UInt32 scene; +@property (nonatomic, copy) NSString *action; +@property (nonatomic, copy) NSString *reserved; +@property (nonatomic, copy, nullable) NSString *openId; + +@end + +#pragma mark - WXSubscribeMiniProgramMsg +/** ! @brief 第三方请求订阅小程序消息 + * + */ +@interface WXSubscribeMiniProgramMsgReq : BaseReq +@property (nonatomic, copy) NSString *miniProgramAppid; +@end + +#pragma mark - WXSubscriptionReq +@interface WXSubscribeMiniProgramMsgResp : BaseResp + +@property(nonatomic, copy) NSString *openId; // 小程序openid +@property(nonatomic, copy) NSString *unionId; // unionId +@property(nonatomic, copy) NSString *nickName; // 用户昵称 + +@end + +#pragma mark - WXinvoiceAuthInsertReq +@interface WXInvoiceAuthInsertReq : BaseReq + +@property (nonatomic, copy) NSString *urlString; + +@end + +#pragma mark - WXinvoiceAuthInsertResp + +@interface WXInvoiceAuthInsertResp : BaseResp + +@property (nonatomic, copy) NSString *wxOrderId; + +@end + +#pragma mark - WXMediaMessage + +/*! @brief 多媒体消息结构体 + * + * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 + */ +@interface WXMediaMessage : NSObject + ++ (WXMediaMessage *)message; + +/** 标题 + * @note 长度不能超过512字节 + */ +@property (nonatomic, copy) NSString *title; +/** 描述内容 + * @note 长度不能超过1K + */ +@property (nonatomic, copy) NSString *description; +/** 缩略图数据 + * @note 大小不能超过64K + */ +@property (nonatomic, strong, nullable) NSData *thumbData; +/** + * @note 长度不能超过64字节 + */ +@property (nonatomic, copy, nullable) NSString *mediaTagName; +/** + * + */ +@property (nonatomic, copy, nullable) NSString *messageExt; +@property (nonatomic, copy, nullable) NSString *messageAction; +/** + * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 + */ +@property (nonatomic, strong) id mediaObject; + +/*! @brief 设置消息缩略图的方法 + * + * @param image 缩略图 + * @note 大小不能超过64K + */ +- (void)setThumbImage:(UIImage *)image; + +@end + + + +#pragma mark - WXImageObject +/*! @brief 多媒体消息中包含的图片数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 + * @note imageData成员不能为空 + * @see WXMediaMessage + */ +@interface WXImageObject : NSObject +/*! @brief 返回一个WXImageObject对象 + * + * @note 返回的WXImageObject对象是自动释放的 + */ ++ (WXImageObject *)object; + +/** 图片真实数据内容 + * @note 大小不能超过25M + */ +@property (nonatomic, strong) NSData *imageData; + +@end + + +#pragma mark - WXMusicObject +/*! @brief 多媒体消息中包含的音乐数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 + * @note musicUrl和musicLowBandUrl成员不能同时为空。 + * @see WXMediaMessage + */ +@interface WXMusicObject : NSObject +/*! @brief 返回一个WXMusicObject对象 + * + * @note 返回的WXMusicObject对象是自动释放的 + */ ++ (WXMusicObject *)object; + +/** 音乐网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicUrl; +/** 音乐lowband网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicLowBandUrl; +/** 音乐数据url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicDataUrl; + +/**音乐lowband数据url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *musicLowBandDataUrl; + +/**音乐封面图Url + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *songAlbumUrl; + +/**歌词信息 LRC格式 + * @note 长度不能超过32K + */ +@property (nonatomic, copy, nullable) NSString *songLyric; +@end + + + +#pragma mark - WXVideoObject +/*! @brief 多媒体消息中包含的视频数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 + * @note videoUrl和videoLowBandUrl不能同时为空。 + * @see WXMediaMessage + */ +@interface WXVideoObject : NSObject +/*! @brief 返回一个WXVideoObject对象 + * + * @note 返回的WXVideoObject对象是自动释放的 + */ ++ (WXVideoObject *)object; + +/** 视频网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *videoUrl; +/** 视频lowband网页的url地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *videoLowBandUrl; + +@end + + + +#pragma mark - WXWebpageObject +/*! @brief 多媒体消息中包含的网页数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 + * @see WXMediaMessage + */ +@interface WXWebpageObject : NSObject +/*! @brief 返回一个WXWebpageObject对象 + * + * @note 返回的WXWebpageObject对象是自动释放的 + */ ++ (WXWebpageObject *)object; + +/** 网页的url地址 + * @note 不能为空且长度不能超过10K + */ +@property (nonatomic, copy) NSString *webpageUrl; + +@end + + + +#pragma mark - WXAppExtendObject +/*! @brief 多媒体消息中包含的App扩展数据对象 + * + * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, + * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 + * @note url,extInfo和fileData不能同时为空 + * @see WXMediaMessage + */ +@interface WXAppExtendObject : NSObject +/*! @brief 返回一个WXAppExtendObject对象 + * + * @note 返回的WXAppExtendObject对象是自动释放的 + */ ++ (WXAppExtendObject *)object; + +/** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 + * @note 长度不能超过10K + */ +@property (nonatomic, copy) NSString *url; +/** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 + * @note 长度不能超过2K + */ +@property (nonatomic, copy, nullable) NSString *extInfo; +/** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 + * @note 大小不能超过10M + */ +@property (nonatomic, strong, nullable) NSData *fileData; + +@end + + + +#pragma mark - WXEmoticonObject +/*! @brief 多媒体消息中包含的表情数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 + * @see WXMediaMessage + */ +@interface WXEmoticonObject : NSObject + +/*! @brief 返回一个WXEmoticonObject对象 + * + * @note 返回的WXEmoticonObject对象是自动释放的 + */ ++ (WXEmoticonObject *)object; + +/** 表情真实数据内容 + * @note 大小不能超过10M + */ +@property (nonatomic, strong) NSData *emoticonData; + +@end + + + +#pragma mark - WXFileObject +/*! @brief 多媒体消息中包含的文件数据对象 + * + * @see WXMediaMessage + */ +@interface WXFileObject : NSObject + +/*! @brief 返回一个WXFileObject对象 + * + * @note 返回的WXFileObject对象是自动释放的 + */ ++ (WXFileObject *)object; + +/** 文件后缀名 + * @note 长度不超过64字节 + */ +@property (nonatomic, copy) NSString *fileExtension; + +/** 文件真实数据内容 + * @note 大小不能超过10M + */ +@property (nonatomic, strong) NSData *fileData; + +@end + + +#pragma mark - WXLocationObject +/*! @brief 多媒体消息中包含的地理位置数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的地理位置数据对象。 + * @see WXMediaMessage + */ +@interface WXLocationObject : NSObject + +/*! @brief 返回一个WXLocationObject对象 + * + * @note 返回的WXLocationObject对象是自动释放的 + */ ++ (WXLocationObject *)object; + +/** 地理位置信息 + * @note 经纬度 + */ +@property (nonatomic, assign) double lng; //经度 +@property (nonatomic, assign) double lat; //纬度 + +@end + +#pragma mark - WXTextObject +/*! @brief 多媒体消息中包含的文本数据对象 + * + * 微信终端和第三方程序之间传递消息中包含的文本数据对象。 + * @see WXMediaMessage + */ +@interface WXTextObject : NSObject + +/*! @brief 返回一个WXTextObject对象 + * + * @note 返回的WXTextObject对象是自动释放的 + */ ++ (WXTextObject *)object; + +/** 地理位置信息 + * @note 文本内容 + */ +@property (nonatomic, copy) NSString *contentText; + +@end + +#pragma mark - WXMiniProgramObject + +@interface WXMiniProgramObject : NSObject + +/*! @brief WXMiniProgramObject对象 + * + * @note 返回的WXMiniProgramObject对象是自动释放的 + */ ++ (WXMiniProgramObject *)object; + +/** 低版本网页链接 + * @attention 长度不能超过1024字节 + */ +@property (nonatomic, copy) NSString *webpageUrl; + +/** 小程序username */ +@property (nonatomic, copy) NSString *userName; + +/** 小程序页面的路径 + * @attention 不填默认拉起小程序首页 + */ +@property (nonatomic, copy, nullable) NSString *path; + +/** 小程序新版本的预览图 + * @attention 大小不能超过128k + */ +@property (nonatomic, strong, nullable) NSData *hdImageData; + +/** 是否使用带 shareTicket 的转发 */ +@property (nonatomic, assign) BOOL withShareTicket; + +/** 分享小程序的版本 + * @attention (正式,开发,体验) + */ +@property (nonatomic, assign) WXMiniProgramType miniProgramType; + +/** 是否禁用转发 */ +@property (nonatomic, assign) BOOL disableForward; + +@end + +#pragma mark - WXLaunchMiniProgramReq + +/*! @brief WXLaunchMiniProgramReq对象, 可实现通过sdk拉起微信小程序 + * + * @note 返回的WXLaunchMiniProgramReq对象是自动释放的 + */ +@interface WXLaunchMiniProgramReq : BaseReq + ++ (WXLaunchMiniProgramReq *)object; + +/** 小程序username */ +@property (nonatomic, copy) NSString *userName; + +/** 小程序页面的路径 + * @attention 不填默认拉起小程序首页 + */ +@property (nonatomic, copy, nullable) NSString *path; + +/** 分享小程序的版本 + * @attention (正式,开发,体验) + */ +@property (nonatomic, assign) WXMiniProgramType miniProgramType; + +/** ext信息 + * @attention json格式 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; + +/** extDic + * @attention 字典,可存放图片等比较大的数据 + */ +@property (nonatomic, copy, nullable) NSDictionary *extDic; + +@end + +#pragma mark - WXLaunchMiniProgramResp +/*! @brief 微信终端向第三方程序返回的WXLaunchMiniProgramReq处理结果。 + * + * 第三方程序向微信终端发送WXLaunchMiniProgramReq后,微信发送回来的处理结果,该结果用WXLaunchMiniProgramResp表示。 + */ +@interface WXLaunchMiniProgramResp : BaseResp + +@property (nonatomic, copy, nullable) NSString *extMsg; + +@end + + +#pragma mark - WXOpenBusinessViewReq +/*! @brief WXOpenBusinessViewReq对象, 可实现第三方通知微信启动,打开业务页面 + * + * @note 返回的WXOpenBusinessViewReq对象是自动释放的 + */ + +@interface WXOpenBusinessViewReq : BaseReq + ++ (WXOpenBusinessViewReq *)object; + +/** 业务类型 + */ +@property (nonatomic, copy) NSString *businessType; + +/** 业务参数 + */ +@property (nonatomic, copy, nullable) NSString *query; + +/** ext信息 + * @note 选填,json格式 + */ +@property (nonatomic, copy, nullable) NSString *extInfo; + +/** extData数据 + * @note + */ +@property (nonatomic, strong, nullable) NSData *extData; +@end + + +@interface WXOpenBusinessViewResp : BaseResp + +/** 业务类型 + */ +@property (nonatomic, copy) NSString *businessType; + +/** 业务返回数据 + */ +@property (nonatomic, copy, nullable) NSString *extMsg; + +@end +NS_ASSUME_NONNULL_END diff --git a/ios/WechatAuthSDK.h b/ios/WechatAuthSDK.h new file mode 100644 index 0000000..308aaea --- /dev/null +++ b/ios/WechatAuthSDK.h @@ -0,0 +1,68 @@ +// +// WechatAuthSDK.h +// WechatAuthSDK +// +// Created by 李凯 on 13-11-29. +// Copyright (c) 2013年 Tencent. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +enum AuthErrCode { + WechatAuth_Err_Ok = 0, //Auth成功 + WechatAuth_Err_NormalErr = -1, //普通错误 + WechatAuth_Err_NetworkErr = -2, //网络错误 + WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败 + WechatAuth_Err_Cancel = -4, //用户取消授权 + WechatAuth_Err_Timeout = -5, //超时 +}; + +@protocol WechatAuthAPIDelegate +@optional + +- (void)onAuthGotQrcode:(UIImage *)image; //得到二维码 +- (void)onQrcodeScanned; //二维码被扫描 +- (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode; //成功登录 + +@end + +@interface WechatAuthSDK : NSObject{ + NSString *_sdkVersion; + __weak id _delegate; +} + +@property(nonatomic, weak, nullable) id delegate; +@property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号 + +/*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调 + * + * @param appId 微信开发者ID + * @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同 + * @param timeStamp 时间戳 + * @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔 + * @param signature 签名 + * @param schemeData 会在扫码后拼在scheme后 + * @return 成功返回YES,失败返回NO + 注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。 + */ + +- (BOOL)Auth:(NSString *)appId + nonceStr:(NSString *)nonceStr + timeStamp:(NSString *)timeStamp + scope:(NSString *)scope + signature:(NSString *)signature + schemeData:(nullable NSString *)schemeData; + + +/*! @brief 暂停登录请求 + * + * @return 成功返回YES,失败返回NO。 + */ +- (BOOL)StopAuth; + +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/libWeChatSDK.a b/ios/libWeChatSDK.a new file mode 100644 index 0000000..66b3398 Binary files /dev/null and b/ios/libWeChatSDK.a differ