|
@@ -8,7 +8,7 @@ import axios from 'axios'
|
|
|
|
|
|
export const WxLogin = (url = '/') => {
|
|
export const WxLogin = (url = '/') => {
|
|
const appid = 'wxe87236d542cd0f94'
|
|
const appid = 'wxe87236d542cd0f94'
|
|
- const URL = 'https://luojigou.vip/training/#' + url
|
|
|
|
|
|
+ const URL = 'https://luojigou.vip/training-test//#' + url
|
|
const redirect_uri = encodeURIComponent(URL)
|
|
const redirect_uri = encodeURIComponent(URL)
|
|
const state = 1
|
|
const state = 1
|
|
window.location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?&appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`)
|
|
window.location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?&appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`)
|
|
@@ -31,42 +31,89 @@ export function getQueryString (name) {
|
|
// axios.get(`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${wxe87236d542cd0f94}&secret=SECRET&code=CODE&grant_type=authorization_code`)
|
|
// axios.get(`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${wxe87236d542cd0f94}&secret=SECRET&code=CODE&grant_type=authorization_code`)
|
|
// }
|
|
// }
|
|
|
|
|
|
-/**
|
|
|
|
- *
|
|
|
|
- * @description 获取用户地理位置
|
|
|
|
- *
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-export function getLocation () {
|
|
|
|
|
|
+// 注册使用wx jsapi的接口
|
|
|
|
+export function registerWxConfig () {
|
|
return new Promise(async (resolve, reject) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
const r = await axios.get(`/zd-api//user-training/h5/visitor/wechat/location?url=${encodeURIComponent(window.location.href.split('#')[0])}`)
|
|
const r = await axios.get(`/zd-api//user-training/h5/visitor/wechat/location?url=${encodeURIComponent(window.location.href.split('#')[0])}`)
|
|
-
|
|
|
|
const data = r.data.data
|
|
const data = r.data.data
|
|
- // console.log(data, 'data');
|
|
|
|
wx.config({
|
|
wx.config({
|
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
appId: data.appId, // 必填,公众号的唯一标识
|
|
appId: data.appId, // 必填,公众号的唯一标识
|
|
timestamp: data.timestamp, // 必填,生成签名的时间戳
|
|
timestamp: data.timestamp, // 必填,生成签名的时间戳
|
|
nonceStr: data.nonceStr, // 必填,生成签名的随机串
|
|
nonceStr: data.nonceStr, // 必填,生成签名的随机串
|
|
signature: data.signature, // 必填,签名
|
|
signature: data.signature, // 必填,签名
|
|
- jsApiList: ['getLocation'] // 必填,需要使用的JS接口列表
|
|
|
|
|
|
+ jsApiList: ['getLocation', 'chooseImage', 'uploadImage'] // 必填,需要使用的JS接口列表
|
|
})
|
|
})
|
|
-
|
|
|
|
wx.ready(() => {
|
|
wx.ready(() => {
|
|
- wx.getLocation({
|
|
|
|
- type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
|
|
|
- success: function (res) {
|
|
|
|
- console.log(res, 'wgs84')
|
|
|
|
- // var latitude = res.latitude // 纬度,浮点数,范围为90 ~ -90
|
|
|
|
- // var longitude = res.longitude // 经度,浮点数,范围为180 ~ -180。
|
|
|
|
- // var speed = res.speed // 速度,以米/每秒计
|
|
|
|
- // var accuracy = res.accuracy // 位置精度
|
|
|
|
- resolve(res)
|
|
|
|
- },
|
|
|
|
- fail: (err) => {
|
|
|
|
- reject(err)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ resolve()
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 本地图片置换 server localId -> serverId
|
|
|
|
+export const getServerIdByLocalId = async (localId) => {
|
|
|
|
+ return new Promise((resolve) => {
|
|
|
|
+ wx.uploadImage({
|
|
|
|
+ localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
|
|
+ isShowProgressTips: 1, // 默认为1,显示进度提示
|
|
|
|
+ success: (res) => {
|
|
|
|
+ const { serverId } = res // 返回图片的服务器端ID
|
|
|
|
+ resolve(serverId)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ * @description 获取用户地理位置
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+// export function getLocation () {
|
|
|
|
+// return new Promise(async (resolve, reject) => {
|
|
|
|
+// const r = await axios.get(`/zd-api//user-training/h5/visitor/wechat/location?url=${encodeURIComponent(window.location.href.split('#')[0])}`)
|
|
|
|
+
|
|
|
|
+// const data = r.data.data
|
|
|
|
+// // console.log(data, 'data');
|
|
|
|
+// wx.config({
|
|
|
|
+// debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
|
+// appId: data.appId, // 必填,公众号的唯一标识
|
|
|
|
+// timestamp: data.timestamp, // 必填,生成签名的时间戳
|
|
|
|
+// nonceStr: data.nonceStr, // 必填,生成签名的随机串
|
|
|
|
+// signature: data.signature, // 必填,签名
|
|
|
|
+// jsApiList: ['getLocation'] // 必填,需要使用的JS接口列表
|
|
|
|
+// })
|
|
|
|
+
|
|
|
|
+// wx.ready(() => {
|
|
|
|
+// wx.getLocation({
|
|
|
|
+// type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
|
|
|
+// success: function (res) {
|
|
|
|
+// console.log(res, 'wgs84')
|
|
|
|
+// // var latitude = res.latitude // 纬度,浮点数,范围为90 ~ -90
|
|
|
|
+// // var longitude = res.longitude // 经度,浮点数,范围为180 ~ -180。
|
|
|
|
+// // var speed = res.speed // 速度,以米/每秒计
|
|
|
|
+// // var accuracy = res.accuracy // 位置精度
|
|
|
|
+// resolve(res)
|
|
|
|
+// },
|
|
|
|
+// fail: (err) => {
|
|
|
|
+// reject(err)
|
|
|
|
+// }
|
|
|
|
+// })
|
|
|
|
+// })
|
|
|
|
+// })
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+export function getLocation () {
|
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
|
+ wx.getLocation({
|
|
|
|
+ type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
|
|
|
+ success: function (res) {
|
|
|
|
+ resolve(res)
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ reject(err)
|
|
|
|
+ }
|
|
})
|
|
})
|
|
})
|
|
})
|
|
}
|
|
}
|