mirror of
https://github.com/little-snow-fox/react-native-wechat-lib.git
synced 2025-12-06 23:36:49 +08:00
feat 添加一次性订阅消息接口
This commit is contained in:
parent
bf5834884e
commit
48d4b7f5b0
11
README.md
11
README.md
@ -364,6 +364,17 @@ Sends request for proceeding payment, then returns an object:
|
|||||||
| errCode | Number | 0 if authorization successed |
|
| errCode | Number | 0 if authorization successed |
|
||||||
| errStr | String | Error message if any error occurred |
|
| errStr | String | Error message if any error occurred |
|
||||||
|
|
||||||
|
#### subscribeMessage(SubscribeMessageMetadata) 一次性订阅消息
|
||||||
|
|
||||||
|
- returns {Object}
|
||||||
|
|
||||||
|
|
||||||
|
| name | type | description |
|
||||||
|
|---------|--------|-------------------------------------|
|
||||||
|
| scene | Number | 重定向后会带上 scene 参数,开发者可以填 0-10000 的整形值,用来标识订阅场值 |
|
||||||
|
| templateId | String | 订阅消息模板 ID,在微信开放平台提交应用审核通过后获得 |
|
||||||
|
| reserved | String | 用于保持请求和回调的状态,授权请后原样带回给第三方。该参数可用于防止 csrf 攻击(跨站请求伪造攻击),建议第三方带上该参数,可设置为简单的随机数加 session 进行校验,开发者可以填写 a-zA-Z0-9 的参数值,最多 128 字节,要求做 urlencode |
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
|
|||||||
@ -515,6 +515,20 @@ public class WeChatModule extends ReactContextBaseJavaModule implements IWXAPIEv
|
|||||||
if (!success) callback.invoke(INVALID_ARGUMENT);
|
if (!success) callback.invoke(INVALID_ARGUMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一次性订阅消息
|
||||||
|
* @param data
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
@ReactMethod
|
||||||
|
public void subscribeMessage(ReadableMap data, Callback callback) {
|
||||||
|
SubscribeMessage.Req req = new SubscribeMessage.Req();
|
||||||
|
req.scene = data.hasKey("scene") ? data.getInt("scene") : SendMessageToWX.Req.WXSceneSession;
|
||||||
|
req.templateID = data.getString("templateId");
|
||||||
|
req.reserved = data.getString("reserved");
|
||||||
|
callback.invoke(null, api.sendReq(req));
|
||||||
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void shareToSession(ReadableMap data, Callback callback) {
|
public void shareToSession(ReadableMap data, Callback callback) {
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
|
|||||||
10
index.d.ts
vendored
10
index.d.ts
vendored
@ -112,6 +112,13 @@ declare module "react-native-wechat-lib" {
|
|||||||
miniProgramType?: number,
|
miniProgramType?: number,
|
||||||
path?: string
|
path?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SubscribeMessageMetadata {
|
||||||
|
scene?: WXScene,
|
||||||
|
templateId: string,
|
||||||
|
reserved?: string
|
||||||
|
}
|
||||||
|
|
||||||
export function shareText(
|
export function shareText(
|
||||||
message: ShareTextMetadata
|
message: ShareTextMetadata
|
||||||
): Promise<{ errCode?: number; errStr?: string }>;
|
): Promise<{ errCode?: number; errStr?: string }>;
|
||||||
@ -136,6 +143,9 @@ declare module "react-native-wechat-lib" {
|
|||||||
export function launchMiniProgram(
|
export function launchMiniProgram(
|
||||||
message: LaunchMiniProgramMetadata
|
message: LaunchMiniProgramMetadata
|
||||||
): Promise<{ errCode?: number; errStr?: string }>;
|
): Promise<{ errCode?: number; errStr?: string }>;
|
||||||
|
export function subscribeMessage(
|
||||||
|
message: SubscribeMessageMetadata
|
||||||
|
): Promise<{ errCode?: number; errStr?: string }>;
|
||||||
export interface PaymentLoad {
|
export interface PaymentLoad {
|
||||||
partnerId: string;
|
partnerId: string;
|
||||||
prepayId: string;
|
prepayId: string;
|
||||||
|
|||||||
23
index.js
23
index.js
@ -156,6 +156,8 @@ const nativeShareMusic = wrapApi(WeChat.shareMusic);
|
|||||||
const nativeShareVideo = wrapApi(WeChat.shareVideo);
|
const nativeShareVideo = wrapApi(WeChat.shareVideo);
|
||||||
const nativeShareWebpage = wrapApi(WeChat.shareWebpage);
|
const nativeShareWebpage = wrapApi(WeChat.shareWebpage);
|
||||||
const nativeShareMiniProgram = wrapApi(WeChat.shareMiniProgram);
|
const nativeShareMiniProgram = wrapApi(WeChat.shareMiniProgram);
|
||||||
|
const nativeSubscribeMessage = wrapApi(WeChat.subscribeMessage);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method sendAuthRequest
|
* @method sendAuthRequest
|
||||||
@ -350,6 +352,27 @@ export function launchMiniProgram({userName, miniProgramType = 0, path = ''}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一次性订阅消息
|
||||||
|
* @method shareVideo
|
||||||
|
* @param {Object} data
|
||||||
|
*/
|
||||||
|
export function subscribeMessage(data) {
|
||||||
|
if (data && data.scene == null) {
|
||||||
|
data.scene = 0
|
||||||
|
}
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
nativeSubscribeMessage(data);
|
||||||
|
emitter.once('WXSubscribeMsgReq.Resp', resp => {
|
||||||
|
if (resp.errCode === 0) {
|
||||||
|
resolve(resp);
|
||||||
|
} else {
|
||||||
|
reject(new WechatError(resp));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share something to favorite
|
* Share something to favorite
|
||||||
* @method shareToFavorite
|
* @method shareToFavorite
|
||||||
|
|||||||
@ -459,6 +459,23 @@ RCT_EXPORT_METHOD(shareMiniProgram:(NSDictionary *)data
|
|||||||
[WXApi sendReq:req completion:completion];
|
[WXApi sendReq:req completion:completion];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 一次性订阅消息
|
||||||
|
RCT_EXPORT_METHOD(subscribeMessage:(NSDictionary *)data
|
||||||
|
:(RCTResponseSenderBlock)callback)
|
||||||
|
{
|
||||||
|
WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
|
||||||
|
req.scene = [data[@"scene"] integerValue];
|
||||||
|
req.templateId = data[@"templateId"];
|
||||||
|
req.reserved = data[@"reserved"];
|
||||||
|
void ( ^ completion )( BOOL );
|
||||||
|
completion = ^( BOOL success )
|
||||||
|
{
|
||||||
|
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
[WXApi sendReq:req completion:completion];
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(launchMiniProgram:(NSDictionary *)data
|
RCT_EXPORT_METHOD(launchMiniProgram:(NSDictionary *)data
|
||||||
:(RCTResponseSenderBlock)callback)
|
:(RCTResponseSenderBlock)callback)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-wechat-lib",
|
"name": "react-native-wechat-lib",
|
||||||
"version": "1.1.12",
|
"version": "1.1.13",
|
||||||
"description": "react-native library for wechat app. 支持分享和拉起小程序。",
|
"description": "react-native library for wechat app. 支持分享和拉起小程序。",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user