|
@@ -6,16 +6,95 @@ import * as WeChat from "react-native-wechat";
|
|
|
*/
|
|
|
WeChat.registerApp("wx51acc19c8f7a0f6f");
|
|
|
export default class wechat {
|
|
|
- componentWillMount() {}
|
|
|
+
|
|
|
+ * 好友文字分享
|
|
|
+ * @param {string} descriptiontext 测试微信好友分享的文本内容
|
|
|
+ */
|
|
|
+ static shareToSessionText(descriptiontext) {
|
|
|
+ WeChat.isWXAppInstalled().then(isInstalled => {
|
|
|
+ if (isInstalled) {
|
|
|
+ WeChat.shareToSession({
|
|
|
+ type: "text",
|
|
|
+ description: descriptiontext
|
|
|
+ }).catch(error => {
|
|
|
+ console.log(error.message);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ alert("请安装微信");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- static shareToSession(text, description) {
|
|
|
- console.log("123123123123123");
|
|
|
+
|
|
|
+ * 微信好友分享链接
|
|
|
+ * @param {string} title_text 分享的标题
|
|
|
+ * @param {string} description_text 分享的标题内容
|
|
|
+ * @param {string} thumbImage_url 分享的标题图片
|
|
|
+ * @param {string} webpageUrl_url 分享的链接
|
|
|
+ */
|
|
|
+ static shareToSessionNews(
|
|
|
+ title_text,
|
|
|
+ description_text,
|
|
|
+ thumbImage_url,
|
|
|
+ webpageUrl_url
|
|
|
+ ) {
|
|
|
WeChat.isWXAppInstalled().then(isInstalled => {
|
|
|
if (isInstalled) {
|
|
|
WeChat.shareToSession({
|
|
|
+ title: title,
|
|
|
+ description: description,
|
|
|
+ thumbImage: thumbImage,
|
|
|
+ type: "news",
|
|
|
+ webpageUrl: webpageUrl
|
|
|
+ }).catch(error => {
|
|
|
+ alert(error.message);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ alert("请安装微信");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 微信朋友圈分享的文本
|
|
|
+ * @param {string} description_text 测试微信朋友圈分享的文本内容
|
|
|
+ */
|
|
|
+ static shareToTimelineText(description_text) {
|
|
|
+ WeChat.isWXAppInstalled().then(isInstalled => {
|
|
|
+ if (isInstalled) {
|
|
|
+ WeChat.shareToTimeline({
|
|
|
type: "text",
|
|
|
- description: "测试微信好友分享的文本内容"
|
|
|
+ description: description_text
|
|
|
+ }).catch(error => {
|
|
|
+ console.log(error.message);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ alert("请安装微信");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 微信好友分享链接
|
|
|
+ * @param {string} title_text 分享的标题
|
|
|
+ * @param {string} description_text 分享的标题内容
|
|
|
+ * @param {string} thumbImage_url 分享的标题图片
|
|
|
+ * @param {string} webpageUrl_url 分享的链接
|
|
|
+ */
|
|
|
+ static shareToTimelineNews(
|
|
|
+ title_text,
|
|
|
+ description_text,
|
|
|
+ thumbImage_url,
|
|
|
+ webpageUrl_url
|
|
|
+ ) {
|
|
|
+ WeChat.isWXAppInstalled().then(isInstalled => {
|
|
|
+ if (isInstalled) {
|
|
|
+ WeChat.shareToTimeline({
|
|
|
+ title: title_text,
|
|
|
+ description: description_text,
|
|
|
+ thumbImage: thumbImage_url,
|
|
|
+ type: "news",
|
|
|
+ webpageUrl: webpageUrl_url
|
|
|
}).catch(error => {
|
|
|
console.log(error.message);
|
|
|
});
|
|
@@ -24,4 +103,39 @@ export default class wechat {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 微信支付
|
|
|
+ * @param {string} partnerId 商家向财付通申请的商家id
|
|
|
+ * @param {string} prepayId 预支付订单
|
|
|
+ * @param {string} nonceStr 随机串,防重发
|
|
|
+ * @param {string} timeStamp 时间戳,防重发.
|
|
|
+ * @param {string} package 商家根据财付通文档填写的数据和签名
|
|
|
+ * @param {string} sign 商家根据微信开放平台文档对数据做的签名
|
|
|
+ */
|
|
|
+ static pay(partnerId, prepayId, nonceStr, timeStamp, packages, sign) {
|
|
|
+ WeChat.isWXAppInstalled().then(isInstalled => {
|
|
|
+ if (isInstalled) {
|
|
|
+ WeChat.pay({
|
|
|
+ partnerId: partnerId,
|
|
|
+ prepayId: prepayId,
|
|
|
+ nonceStr: nonceStr,
|
|
|
+ timeStamp: timeStamp,
|
|
|
+ package: packages,
|
|
|
+ sign: sign
|
|
|
+ })
|
|
|
+ .then(requestJson => {
|
|
|
+
|
|
|
+ if (requestJson.errCode == "0") {
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ alert("支付失败");
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ alert("请安装微信");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|