初始化仓库

This commit is contained in:
wangxiaowei
2026-04-14 16:54:04 +08:00
commit 967c25b397
553 changed files with 106514 additions and 0 deletions

197
utils/wechath5.js Normal file
View File

@ -0,0 +1,197 @@
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
// #ifdef H5
import weixin from '@/js_sdk/jweixin-module'
import { isAndroid } from './tools'
import { getJsconfig, getCodeUrl, wechatLogin } from '@/api/app'
import store from '../store'
import Cache from './cache'
class Wechath5 {
//获取微信配置url
signLink() {
if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
window.entryUrl = location.href.split('#')[0]
}
console.log(location.href.split('#')[0])
return isAndroid() ? location.href.split('#')[0] : window.entryUrl
}
//微信sdk配置
config() {
return new Promise((resolve) => {
getJsconfig().then((res) => {
if (res.code == 1) {
let config = res.data.config
weixin.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来若要查看传入的参数可以在pc端打开参数信息会通过log打出仅在pc端时才会打印。
appId: config.appId, // 必填,公众号的唯一标识
timestamp: config.timestamp, // 必填,生成签名的时间戳
nonceStr: config.nonceStr, // 必填,生成签名的随机串
signature: config.signature, // 必填,签名
jsApiList: config.jsApiList // 必填需要使用的JS接口列表
})
resolve()
}
})
})
}
//获取微信登录url
getWxUrl() {
getCodeUrl().then((res) => {
if (res.code == 1) {
location.href = res.data.url
}
})
}
//微信授权
authLogin(code) {
return new Promise((resolve, reject) => {
wechatLogin({
code
}).then((res) => {
if (res.code == 1) {
store.commit('login', {
token: res.data.token
})
resolve(res.data)
}
})
})
}
//微信分享
share(option) {
weixin.ready(() => {
const { shareTitle, shareLink, shareImage, shareDesc } = option
weixin.updateTimelineShareData({
title: shareTitle, // 分享标题
link: shareLink, // 分享链接该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareImage, // 分享图标
success: function (res) {
// 设置成功
}
})
// 发送给好友
weixin.updateAppMessageShareData({
title: shareTitle, // 分享标题
link: shareLink, // 分享链接该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareImage, // 分享图标
desc: shareDesc,
success: function (res) {
// 设置成功
}
})
// 发送到tx微博
weixin.onMenuShareWeibo({
title: shareTitle, // 分享标题
link: shareLink, // 分享链接该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareImage, // 分享图标
desc: shareDesc,
success: function (res) {
// 设置成功
}
})
})
}
wxPay(opt) {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.chooseWXPay({
timestamp: opt.timeStamp, // 支付签名时间戳注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr: opt.nonceStr, // 支付签名随机串,不长于 32 位
package: opt.package, // 统一支付接口返回的prepay_id参数值提交格式如prepay_id=***
signType: opt.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign: opt.paySign, // 支付签名
success: (res) => {
console.log(res)
reslove()
},
cancel: (res) => {
reject()
},
fail: (res) => {
reject()
}
})
})
})
}
getWxAddress() {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.openAddress({
success: (res) => {
reslove(res)
}
})
})
})
}
getLocation() {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.getLocation({
type: 'gcj02',
success: (res) => {
reslove(res)
},
fail: (res) => {
reject(res)
}
})
})
})
}
reviceTransfer(mchId, appId, packageInfo) {
return new Promise((reslove, reject) => {
weixin.ready(() => {
weixin.checkJsApi({
jsApiList: ['requestMerchantTransfer'],
success: function (res) {
if (res.checkResult['requestMerchantTransfer']) {
WeixinJSBridge.invoke(
'requestMerchantTransfer',
{
mchId,
appId,
package: packageInfo
},
function (res) {
if (res.err_msg === 'requestMerchantTransfer:ok') {
reslove(res.err_msg)
} else {
reject(res.err_msg)
}
}
)
} else {
alert('你的微信版本过低,请更新至最新版本。')
}
}
})
})
})
}
}
export default new Wechath5()
// #endif