Commit c5f7ebdc by 李静静

引流链接

parent 84db7131
//app.js
import {request} from "./utils/request.js"
App({
onLaunch: function () {
// if (!wx.cloud) {
// console.error('请使用 2.2.3 或以上的基础库以使用云能力')
// } else {
// wx.cloud.init({
// // env 参数说明:
// // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
// // 此处请填入环境 ID, 环境 ID 可打开云控制台查看
// // 如不填则使用默认环境(第一个创建的环境)
// // env: 'my-env-id',
// traceUser: true,
// })
// }
// 登录
wx.login({
success: async (res) => {
const { code } = res
//console.log(code)
// 发送 code 到后台换取 unionId。具体逻辑可查阅:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
try {
const { unionid:unionId } = await this.code2unionId(code)
this.globalData.unionId = unionId
} catch (error) {
// code2unionId 失败也认为登录成功
}
this.globalData.isLogged = true
this.handleSyncGetUnionIdCallback()
}
})
},
code2unionId(code) {
return new Promise((resolve, reject) => {
// NOTE: 以下 code 换取 unionId 的业务逻辑仅供参考,具体逻辑请根据贵司实际情况自行实现
request({
url:"/xcx/login/check_login?ajax=1&code="+code,
// method:"post",
data:{
code
},
success:(res)=>{
console.log(res.data.data)
if(res.data&&res.data.code===0){
this.globalData = {}
resolve( res.data.data )
}
},
fail:(errMsg)=>{
reject(errMsg || 'code2unionId fail')
}
})
})
},
syncGetUnionId() {
const { isLogged, unionId, syncGetUnionIdCallbackList } = this.globalData
if (isLogged) {
return Promise.resolve({ unionId })
}
return new Promise((resolve) => {
syncGetUnionIdCallbackList.push(resolve)
})
},
handleSyncGetUnionIdCallback() {
const { unionId, syncGetUnionIdCallbackList } = this.globalData
syncGetUnionIdCallbackList.forEach((callback) => {
callback({ unionId })
})
this.globalData.syncGetUnionIdCallbackList = []
},
globalData: {
syncGetUnionIdCallbackList: [],
isLogged: false,
unionId: ""
}
})
......@@ -2,7 +2,8 @@
"pages": [
"pages/freeCourse/index",
"pages/joinGroup/index",
"pages/weibanzhushou/index"
"pages/weibanzhushou/index",
"pages/yinliu/externalLink"
],
"plugins": {
"chatGroupPlugin": {
......@@ -23,4 +24,4 @@
},
"sitemapLocation": "sitemap.json",
"style": "v2"
}
\ No newline at end of file
}
// externalLink.js
// 获取应用实例
const app = getApp()
// NOTE: 这里的域名请于管理后台-小程序设置-配置域名中配置的域名保持一致
const baseHost = "https://hrcpjcaabj.miniapp.weibanzhushou.com"
const baseWebViewUrl = `${baseHost}/H5/external_links_wx`
Page({
data: {
webViewUrl: ""
},
// 事件处理函数
async onLoad(pageParams) {
// 同步获取用户 login 后的 unionId
const { unionId } = await app.syncGetUnionId()
console.log(unionId)
// const unionId='o893uwiRhcxNdHfmx19GQW_W9MwM';
// 微伴会在通过小程序 urlscheme.generate 接口生成 scheme 码
// 时,将参数 c 和 hash_id 配置在 jump_wxa.query 中。
// externalLink 页面载入时,会被微信自动加入到页面参数中。
// 具体逻辑可查阅:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
let { c, hash_id, debug } = pageParams
//hash_id='r7p1mtfei'
//c='X1FnUl5BRW0ABwIIWl5tUF1ERQ'
// 不建议对以下 webViewUrl 的拼接代码进行修改,以免遗漏参数
const webViewUrl = `${baseWebViewUrl}?hash_id=${hash_id || ''}&_c=${c || ''}&unionId=${unionId}`
if (!unionId && debug) {
wx.showModal({
title: '提示',
content: '参数错误:缺少 unionId',
})
}
if (debug) {
wx.showModal({
title: 'For debug',
content: webViewUrl
})
}
// 参数 c 和 hash_id 用于公司和引流链接配置的匹配
// 参数 unionId 用于引流链接的访问数据统计
this.setData({ webViewUrl })
// 显示分享按钮,贵司可按需调用
// this.showShareMenu()
},
showShareMenu() {
// 显示分享按钮的逻辑可查阅:https://developers.weixin.qq.com/miniprogram/dev/api/share/wx.showShareMenu.html
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
}
})
{
"usingComponents": {}
}
\ No newline at end of file
<!--externalLink.wxml-->
<web-view src="{{webViewUrl}}"></web-view>
\ No newline at end of file
/**externalLink.wxss**/
//const host='http://ljj.dev.neoteched.com' //开发
const host='https://winterfell-alpha.neoteched.com' //测试
//const host='https://sk2.shenlancity.com' //线上
export const request=({url,method,header,success,fail})=>{
//const host='http://lxlsk.dev.neoteched.com' //开发
//const host='https://winterfell-alpha.neoteched.com' //测试
const host='https://sk2.shenlancity.com' //线上
export const request=({url,data,method,header,success,fail})=>{
if(!url){
console.error('url不能为空')
return
......@@ -12,6 +14,7 @@ export const request=({url,method,header,success,fail})=>{
header: header||{
'content-type': 'application/json',
},
// data:data||null,
success: success||(res=>{
console.log("成功");
console.log(res);
......@@ -20,4 +23,4 @@ export const request=({url,method,header,success,fail})=>{
console.log(res);
})
})
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment