weex-wechat 中文版
Wechat(auth, pay, share) plugin for weex.
weexpack plugin install weex-wechat
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)
}
})
allprojects {
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
If you are going to integrate login or share functions, you need to create a package named 'wxapi' in your application package and a class named WXEntryActivity
Then add the following node to AndroidManifest.xml
:
<manifest>
<application>
<activity
android:name=".wxapi.WXEntryActivity"
android:label="@string/app_name"
android:exported="true"
/>
</application>
</manifest>
If you are going to integrate payment functionality by using this library, then
create a package named also wxapi
in your application package and a class named
WXPayEntryActivity
Then add the following node to AndroidManifest.xml
:
<manifest>
<application>
<activity
android:name=".wxapi.WXPayEntryActivity"
android:label="@string/app_name"
android:exported="true"
/>
</application>
</manifest>
Add "URL Schema" as your app id for "URL type" in Targets > info, See the following screenshot for the view on your XCode.
On iOS 9, add wechat and weixin into LSApplicationQueriesSchemes in Targets > info > Custom iOS Target Properties. Or edit Info.plist then add:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
<string>wechat</string>
</array>
Then copy the following in AppDelegate.m:
- (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]];
}