杨豪
3 years ago
16 changed files with 236 additions and 40 deletions
@ -0,0 +1,82 @@
|
||||
var jweixin = require('jweixin-module') |
||||
export default { |
||||
//判断是否在微信中
|
||||
isWechat: function () { |
||||
var ua = window.navigator.userAgent.toLowerCase(); |
||||
if (ua.match(/micromessenger/i) == 'micromessenger') { |
||||
// console.log(‘是微信客户端‘)
|
||||
return true; |
||||
} else { |
||||
// console.log(‘不是微信客户端‘)
|
||||
return false; |
||||
} |
||||
}, |
||||
//初始化sdk配置
|
||||
initJssdkShare: function (callback, url) { |
||||
uni.request({ |
||||
url: 'http://licai.youma.me/index/wechat/', |
||||
method: 'GET', |
||||
data: { |
||||
url: 'http://licaifrot.youma.me/' |
||||
}, //这里不是统一的,看你们后端
|
||||
success: (res) => { |
||||
console.log(res) |
||||
if (res.statusCode == 200) { |
||||
let result = res.data.Data |
||||
console.log(result) |
||||
jweixin.config({ |
||||
debug: false, |
||||
appId: result.appId, |
||||
timestamp: result.timestamp, |
||||
nonceStr: result.nonceStr, |
||||
signature: result.signature, |
||||
jsApiList: [ |
||||
'chooseWXPay', |
||||
'checkJsApi', |
||||
'updateTimelineShareData', |
||||
'updateAppMessageShareData' |
||||
] |
||||
}); |
||||
//配置完成后,再执行分享等功能
|
||||
if (callback) { |
||||
callback(result); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
//在需要自定义分享的页面中调用
|
||||
share: function (data, url) { |
||||
url = url ? url : window.location.href; |
||||
console.log("url:" + url) |
||||
if (!this.isWechat()) { |
||||
uni.showToast({ |
||||
title: '不在微信客户端', |
||||
icon: 'none' |
||||
}) |
||||
return; |
||||
} |
||||
//每次都需要重新初始化配置,才可以进行分享
|
||||
this.initJssdkShare(function (signData) { |
||||
jweixin.ready(function () { |
||||
var shareData = { |
||||
title: data && data.title ? data.title : signData.site_name, |
||||
desc: data && data.desc ? data.desc : signData.site_description, |
||||
link: url, |
||||
imgUrl: data && data.img ? data.img : signData.site_logo, |
||||
success: function (res) { |
||||
// 分享后的一些操作,比如分享统计等等
|
||||
}, |
||||
cancel: function (res) {} |
||||
}; |
||||
//分享给朋友接口
|
||||
jweixin.updateAppMessageShareData(shareData); |
||||
//分享到朋友圈接口
|
||||
// jweixin.updateTimelineShareData(shareData);
|
||||
}); |
||||
}, url); |
||||
}, |
||||
|
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
# jweixin-module |
||||
|
||||
微信JS-SDK |
||||
|
||||
## 安装 |
||||
|
||||
### NPM |
||||
|
||||
```shell |
||||
npm install jweixin-module --save |
||||
``` |
||||
|
||||
### UMD |
||||
|
||||
```http |
||||
https://unpkg.com/jweixin-module/out/index.js |
||||
``` |
||||
|
||||
## 使用 |
||||
|
||||
```js |
||||
var jweixin = require('jweixin-module') |
||||
jweixin.ready(function(){ |
||||
// TODO |
||||
}); |
||||
``` |
||||
|
||||
## 完整API |
||||
|
||||
>[微信JS-SDK说明文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115) |
File diff suppressed because one or more lines are too long
@ -0,0 +1,54 @@
|
||||
{ |
||||
"_from": "jweixin-module", |
||||
"_id": "jweixin-module@1.6.0", |
||||
"_inBundle": false, |
||||
"_integrity": "sha1-Sn6mFAg+PJw/SeL9wruILPpY380=", |
||||
"_location": "/jweixin-module", |
||||
"_phantomChildren": {}, |
||||
"_requested": { |
||||
"type": "tag", |
||||
"registry": true, |
||||
"raw": "jweixin-module", |
||||
"name": "jweixin-module", |
||||
"escapedName": "jweixin-module", |
||||
"rawSpec": "", |
||||
"saveSpec": null, |
||||
"fetchSpec": "latest" |
||||
}, |
||||
"_requiredBy": [ |
||||
"#USER", |
||||
"/" |
||||
], |
||||
"_resolved": "https://registry.nlark.com/jweixin-module/download/jweixin-module-1.6.0.tgz", |
||||
"_shasum": "4a7ea614083e3c9c3f49e2fdc2bb882cfa58dfcd", |
||||
"_spec": "jweixin-module", |
||||
"_where": "F:\\sqx-bawangcan用户端小程序\\sqx-bawangcan", |
||||
"author": { |
||||
"name": "Shengqiang Guo" |
||||
}, |
||||
"bugs": { |
||||
"url": "https://github.com/zhetengbiji/jweixin-module/issues" |
||||
}, |
||||
"bundleDependencies": false, |
||||
"deprecated": false, |
||||
"description": "微信JS-SDK", |
||||
"devDependencies": {}, |
||||
"homepage": "https://github.com/zhetengbiji/jweixin-module#readme", |
||||
"keywords": [ |
||||
"wxjssdk", |
||||
"weixin", |
||||
"jweixin", |
||||
"wechat", |
||||
"jssdk", |
||||
"wx" |
||||
], |
||||
"license": "ISC", |
||||
"main": "lib/index.js", |
||||
"name": "jweixin-module", |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "git+https://github.com/zhetengbiji/jweixin-module.git" |
||||
}, |
||||
"scripts": {}, |
||||
"version": "1.6.0" |
||||
} |
Loading…
Reference in new issue