-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDemoAlibaichuan.js
204 lines (184 loc) · 5.42 KB
/
DemoAlibaichuan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
Q:交易成功后没有回调
1.详情页加入购物车没有回调
2.只有加入购物车购页加购才有回调
3.支付的话,如果有接入支付宝sdk,都会有回调的
****目前只有通过H5打开页面完成支付,并且集成了alipay的时候才会有支付成功的回调*** (12/7更新)
*/
import React, {PureComponent} from 'react';
import {
InteractionManager
} from 'react-native';
// 引入sdk
import RNAlibcSdk from 'react-native-alibaichuan';
class Alibaichuan extends PureComponent {
constructor(props) {
super(props);
this.state = {
ready: false,
mmpid: 'mm_0000000_0000000_22182111',//三段式
adzoneid: '22182111',//pid三段式最后一段
tkkey: '000000',//阿里妈妈那边网站或者app的appkey
opentype: 'html5',//打开的方式
isvcode: 'app'//必须传
};
}
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
})
}
doAlimama = (str) => {
let that = this;
if (str.match(/^http[s]?:\/\/.+/)) {
//是url
this.showTaokeItemByUrl({
url: str,
opentype: 'html5'
});
} else {
this.showTaokeItemById({
itemid: str
});
}
};
//显示
initSDK = () => {
let that = this;
return new Promise(function (resolve, reject) {
RNAlibcSdk.initTae((err) => {
if (!err)
resolve('init success');
else
reject(err);
});
});
};
showLogin = () => {
return new Promise(function (resolve, reject) {
RNAlibcSdk.showLogin((err, userInfo) => {
if (!err)
resolve(userInfo);
else
reject(err);
})
});
};
isLogin = () => {
return new Promise(function (resolve, reject) {
RNAlibcSdk.isLogin((err, isLogin) => {
if (!err)
resolve(isLogin);
else
reject(err);
})
});
};
getUserInfo = () => {
return new Promise(function (resolve, reject) {
RNAlibcSdk.getUserInfo((err, userInfo) => {
if (!err)
resolve(userInfo);
else
reject(err);
})
});
};
logout = () => {
return new Promise(function (resolve, reject) {
RNAlibcSdk.logout((err) => {
if (!err)
resolve('logout success');
else
reject(err);
})
});
};
showTaokeItemById = (params) => {
params = this.mkParam(params);
RNAlibcSdk.show({
type: 'detail',
payload: params
}, (err, info) => {
if (!err)
console.log(info)
else
console.log(err)
}
);
};
showTaokeItemByUrl = (params) => {
params = this.mkParam(params);
RNAlibcSdk.show({
type: 'url',
payload: params
}, (err, info) => {
if (!err)
console.log(info)
else
console.log(err)
}
);
};
addCartPage = (params) => {
params = this.mkParam(params);
RNAlibcSdk.show({
type: 'addCard',
payload: params
}, (err, info) => {
if (!err)
console.log(info)
else
console.log(err)
}
);
};
shopPage = (params) => {
params = this.mkParam(params);
RNAlibcSdk.show({
type: 'shop',
payload: params
}, (err, info) => {
if (!err)
console.log(info)
else
console.log(err)
}
);
};
myOrdersPage = (params) => {
params = this.mkParam(params);
RNAlibcSdk.show({
type: 'orders',
payload: params
}, (err, info) => {
if (!err)
console.log(info)
else
console.log(err)
}
);
};
myCartsPage = (params) => {
params = this.mkParam(params);
RNAlibcSdk.show({
type: 'mycard',
payload: params
}, (err, info) => {
if (!err)
console.log(info)
else
console.log(err)
}
);
};
//处理参数
mkParam = (param) => {
param.mmpid = (param.mmpid && param.mmpid !== '') ? param.mmpid : this.state.mmpid;
param.adzoneid = (param.adzoneid && param.adzoneid !== '') ? param.adzoneid : this.state.adzoneid;
param.tkkey = (param.tkkey && param.tkkey !== '') ? param.tkkey : this.state.tkkey;
param.opentype = (param.opentype && param.opentype !== '') ? param.opentype : this.state.opentype;
param.isvcode = (param.isvcode && param.isvcode !== '') ? param.isvcode : this.state.isvcode;
return param;
};
}
export default Alibaichuan;