https://github.com/doabit/weex-wechat
Weex plugin for wechat(auth, pay, share).
https://github.com/doabit/weex-wechat
Last synced: 8 months ago
JSON representation
Weex plugin for wechat(auth, pay, share).
- Host: GitHub
- URL: https://github.com/doabit/weex-wechat
- Owner: doabit
- Created: 2017-10-27T14:17:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-12T07:36:15.000Z (about 8 years ago)
- Last Synced: 2025-04-12T23:55:36.728Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 6.84 KB
- Stars: 23
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README-zh.md
Awesome Lists containing this project
README
# weex-wechat
> Wechat(auth, pay, share) plugin for weex.
## 准备工作
```bash
weexpack plugin install weex-wechat
```
## 使用方法
```javascript
var wechat = weex.requireModule('wechat');
var stream = weex.requireModule('stream');
wechat.registerApp("appid", function(data) {
console.log(data, "wx register")
})
wechat.login({}, function(data) {
console.log(data)
})
// share text to timeline (share to session use shareToSession)
wechat.shareToTimeLine({
type: "text",
content: "text content"
}, function(data) {
console.log("text shared", data)
})
// share image to timeline
wechat.shareToTimeLine({
type: "image",
image: imageUrl
}, function(data) {
console.log("image shared", data)
})
// share video to timeline
wechat.shareToTimeLine({
type: "video",
title: 'video title',
content: "video content",
image: imageUrl,
url: 'https://v.qq.com/x/cover/m4cz4v1n0av4a8k/x00223sb1nm.html?new=1'
}, function(data) {
console.log("video shared", data)
})
// share webpage to timeline
wechat.shareToTimeLine({
type: "webpage",
title: 'vebpage title',
content: "webpage content",
image: imageUrl,
url: 'http://github.com/doabit'
}, function(data) {
console.log("web page shared", data)
})
// wxpay
stream.fetch({
method: 'POST',
url: 'http://192.168.1.102:3000/wx_app_pay', //change to your wepay api
type: "json"
}, function(resData){
if (resData.ok) {
var data = resData.data;
wechat.pay({
appid: data.appid,
sign: data.sign,
timestamp: data.timestamp,
noncestr: data.noncestr,
partnerid: data.partnerid,
prepayid: data.prepayid,
packageValue:data.package
}, function(resData){
console.log(resData)
})
} else {
console.log(resData)
}
})
```
## android 配置
### 添加 `jitpack.io` 到 android/build.gradle
```gradle
allprojects {
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
```
### 集成微信登录和分享
集成微信登录和分享,首先创建一个包名为 'wxapi',并且添加一个名为 [WXEntryActivity](https://github.com/doabit/weex-wechat/blob/master/android/WXEntryActivity.java) 的类。
添加下面代码到 `AndroidManifest.xml`:
```xml
```
### 集成微信支付
在 `wxapi`包中添加文件名为 [WXPayEntryActivity](https://github.com/doabit/weex-wechat/blob/master/android/WXPayEntryActivity.java) 的类
添加下面代码到 `AndroidManifest.xml`:
```xml
```
## IOS 配置
在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id(如下图所示)。

iOS 9 往后, 在 Targets > info > Custom iOS Target Properties 中 添加 wechat 和 weixin 到 LSApplicationQueriesSchemes. 或者 直接编辑 Info.plist:
```plist
LSApplicationQueriesSchemes
weixin
wechat
```
添加如下代码到 AppDelegate.m:
```objc
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [WXApi handleOpenURL:url delegate:[WeChatManager shareInstance]];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [WXApi handleOpenURL:url delegate:[WeChatManager shareInstance]];
}
```
## 参考资料
[react-native-wechat](https://github.com/yorkie/react-native-wechat)
[WeexErosFramework](https://github.com/aa453509345/WeexErosFramework)
[微信开放平台](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=1417674108&token=&lang=zh_CN)
## Author
[@doabit](https://github.com/doabit)
## license
[MIT](http://opensource.org/licenses/MIT)