diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..1a5b840 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,60 @@ +export interface ITextShareData { + type: "text"; + text: string; +} + +export interface IImageShareData { + type: "image"; + imageUrl: string; + title: string; + description: string; +} + +export interface IWebShareData { + type: "news"; + imageUrl: string; + webpageUrl: string; + title: string; + description: string; +} + +export interface IPayReq { + partnerId: string; + prepayId: string; + nonceStr: string; + timeStamp: string; + package: string; + sign: string; +} + +export interface IPayResp { + errCode: number; + errMsg: string; + appid: string; + returnKey: string; +} + +export interface ILoginResp { + code: string; + appid: string; + lang: string; + country: string; + errCode?: number; + errMsg?: string; +} + +export function isWXAppInstalled(): Promise; + +export function isWXAppSupportApi(): Promise; + +export function login(data: { scope: string }): Promise; + +export function shareToTimeline( + data: ITextShareData | IImageShareData | IWebShareData +): Promise; + +export function shareToSession( + data: ITextShareData | IImageShareData | IWebShareData +): Promise; + +export function pay(data: IPayReq): Promise; diff --git a/index.js b/index.js index ac27380..1a78c37 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ import { NativeAppEventEmitter, NativeModules } from 'react-native'; -import promisify from 'es6-promisify'; +import Promise from 'bluebird'; const WeChatAPI = NativeModules.WeChatAPI; @@ -57,7 +57,7 @@ function wrapCheckApi(nativeFunc) { return undefined; } - const promisified = promisify(nativeFunc, translateError); + const promisified = Promise.promisify(nativeFunc, translateError); return (...args) => { return promisified(...args); }; @@ -71,7 +71,7 @@ function wrapApi(nativeFunc) { return undefined; } - const promisified = promisify(nativeFunc, translateError); + const promisified = Promise.promisify(nativeFunc, translateError); return async function (...args) { if (!WeChatAPI.isAppRegistered) { throw new Error('注册应用失败'); diff --git a/package.json b/package.json index c22a7d2..b8f1e4b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "homepage": "https://github.com/reactnativecn/react-native-wx#readme", "dependencies": { - "es6-promisify": "^3.0.0" + "bluebird": "^3.5.1" }, "peerDependencies": { "react-native": "^0.33.0"