diff --git a/common/js/auth.js b/common/js/auth.js index b73f8d6..9912bd3 100644 --- a/common/js/auth.js +++ b/common/js/auth.js @@ -39,7 +39,7 @@ export default { }, fail: (res) => { // #ifdef MP-WEIXIN - let scene = wx.getLaunchOptionsSync().scene; + let scene = uni.getLaunchOptionsSync().scene; if ([1154, 1155].indexOf(scene) == -1) { this.$util.showToast({ title: res.errMsg diff --git a/common/js/config.js b/common/js/config.js index 6b27eff..c8dc5a0 100644 --- a/common/js/config.js +++ b/common/js/config.js @@ -1,3 +1,9 @@ +let site = null; +try { + site = require("../site.js"); // 适配发行模式的 site.js 导入 +} catch (e) { + site = null; // 开发模式无 site.js 时赋值为 null +} // 发行版本,配置说明 let releaseCfg = undefined; try { diff --git a/components/common-payment/payment.js b/components/common-payment/payment.js index 2fb1ef2..97a7a5c 100644 --- a/components/common-payment/payment.js +++ b/components/common-payment/payment.js @@ -206,6 +206,7 @@ export default { * 获取订单结算数据 */ payment() { + this.$api.sendRequest({ url: this.api.payment, data: this.handleCreateData(), @@ -214,7 +215,7 @@ export default { let data = res.data; // #ifdef MP-WEIXIN - var scene = uni.getStorageSync('is_test') ? 1175 : wx.getLaunchOptionsSync().scene; + var scene = uni.getStorageSync('is_test') ? 1175 : uni.getLaunchOptionsSync().scene; if ([1175, 1176, 1177, 1191, 1195].indexOf(scene) != -1 && data.delivery.express_type) { data.delivery.express_type = data.delivery.express_type.filter(item => item.name == 'express'); } diff --git a/components/ns-payment/ns-payment.vue b/components/ns-payment/ns-payment.vue index ba31411..eecf859 100644 --- a/components/ns-payment/ns-payment.vue +++ b/components/ns-payment/ns-payment.vue @@ -137,7 +137,7 @@ this.isMatched = 1; return; } - let options = wx.getLaunchOptionsSync(); + let options = uni.getLaunchOptionsSync(); this.$api.sendRequest({ url: '/shopcomponent/api/weapp/scenecheck', data: { @@ -357,7 +357,7 @@ out_trade_no: this.payInfo.out_trade_no, pay_type: payType.type, is_matched: this.isMatched, - scene: uni.getStorageSync('is_test') ? 1175 : wx.getLaunchOptionsSync().scene + scene: uni.getStorageSync('is_test') ? 1175 : uni.getLaunchOptionsSync().scene }, success: res => { uni.hideLoading(); @@ -365,7 +365,7 @@ var payData = res.data.data; // #ifdef MP-WEIXIN - var scene = uni.getStorageSync('is_test') ? 1175 : wx.getLaunchOptionsSync() + var scene = uni.getStorageSync('is_test') ? 1175 : uni.getLaunchOptionsSync() .scene; if ([1175, 1176, 1177, 1191, 1195].indexOf(scene) != -1) { uni.requestOrderPayment({ diff --git a/components/payment/payment.vue b/components/payment/payment.vue index 1e7358f..bdbe1cd 100644 --- a/components/payment/payment.vue +++ b/components/payment/payment.vue @@ -1,610 +1,832 @@ - - - - - - \ No newline at end of file diff --git a/main.js b/main.js index caad937..bdce6de 100644 --- a/main.js +++ b/main.js @@ -1,67 +1,99 @@ -// #ifdef H5 -import './common/js/pc' -// #endif -import Vue from 'vue' -import App from './App' -import store from './store' -import Util from './common/js/util.js' -import Http from './common/js/http.js' -import Lang from './common/js/lang.js' -import Config from './common/js/config.js' -import EventBus from './common/js/event-bus.js' -import DomEventBridge from './common/js/dom-event-bridge.js' -import globalConfig from './common/js/golbalConfig.js'; -import { - uniStorage -} from './common/js/storage.js' - -Vue.prototype.$store = store //挂在vue - -Vue.config.productionTip = false - -Vue.prototype.$util = Util; -Vue.prototype.$api = Http; - -Vue.prototype.$langConfig = Lang; //语言包对象 -Vue.prototype.$lang = Lang.lang; //解析语言包 - -Vue.prototype.$config = Config; - - -// #ifdef H5 -EventBus.setDomBridge(DomEventBridge) -// #endif -Vue.prototype.$eventBus = EventBus; - -Vue.mixin(globalConfig); - -App.mpType = 'app'; - -// 重写存储,增加前缀 -uniStorage(); - -//常用组件 -import loadingCover from '@/components/loading-cover/loading-cover.vue'; -Vue.component('loading-cover', loadingCover); - -import nsEmpty from '@/components/ns-empty/ns-empty.vue'; -Vue.component('ns-empty', nsEmpty); - -import MescrollUni from "@/components/mescroll/my-list-mescroll.vue"; -Vue.component("mescroll-uni", MescrollUni); //上拉加载,下拉刷新组件 - -import MescrollBody from "@/components/mescroll/mescroll-body.vue" -Vue.component('mescroll-body', MescrollBody); - -import NsLogin from "@/components/ns-login/ns-login.vue" -Vue.component('ns-login', NsLogin); - -import PrivacyPopup from '@/components/wx-privacy-popup/privacy-popup.vue'; -Vue.component('privacy-popup', PrivacyPopup) - -const app = new Vue({ - ...App, - store -}) - +// #ifdef H5 +import './common/js/pc' +// #endif +import Vue from 'vue' +import App from './App' +import store from './store' +import Util from './common/js/util.js' +import Http from './common/js/http.js' +import Lang from './common/js/lang.js' +import Config from './common/js/config.js' +import EventBus from './common/js/event-bus.js' +import DomEventBridge from './common/js/dom-event-bridge.js' +import globalConfig from './common/js/golbalConfig.js'; +import { + uniStorage +} from './common/js/storage.js' + +Vue.prototype.$store = store //挂在vue + +Vue.config.productionTip = false + +Vue.prototype.$util = Util; +Vue.prototype.$api = Http; + +Vue.prototype.$langConfig = Lang; //语言包对象 +Vue.prototype.$lang = Lang.lang; //解析语言包 + +Vue.prototype.$config = Config; + +// #ifdef H5 +EventBus.setDomBridge(DomEventBridge) +// #endif +Vue.prototype.$eventBus = EventBus; + +Vue.mixin(globalConfig); + +App.mpType = 'app'; + +// 重写存储,增加前缀 +uniStorage(); + +//常用组件 +import loadingCover from '@/components/loading-cover/loading-cover.vue'; +Vue.component('loading-cover', loadingCover); + +import nsEmpty from '@/components/ns-empty/ns-empty.vue'; +Vue.component('ns-empty', nsEmpty); + +import MescrollUni from "@/components/mescroll/my-list-mescroll.vue"; +Vue.component("mescroll-uni", MescrollUni); //上拉加载,下拉刷新组件 + +import MescrollBody from "@/components/mescroll/mescroll-body.vue" +Vue.component('mescroll-body', MescrollBody); + +import NsLogin from "@/components/ns-login/ns-login.vue" +Vue.component('ns-login', NsLogin); + +import PrivacyPopup from '@/components/wx-privacy-popup/privacy-popup.vue'; +// 只保留一次组件注册(删除重复行) +Vue.component('privacy-popup', PrivacyPopup) + +// 全局登录方法(替换成你的真实后端接口地址) +Vue.prototype.$doGlobalLogin = async function() { + return new Promise((resolve, reject) => { + uni.login({ + success: async (loginRes) => { + if (!loginRes.code) { + reject("获取登录凭证失败,请重试"); + return; + } + try { + // !!替换为你的真实后端登录接口地址!! + const res = await uni.request({ + url: "https://dev.aigc-quickapp.com/api/user/login", + method: "POST", + data: { code: loginRes.code } + }); + if (res.data?.success) { + uni.setStorageSync("token", res.data.token); + resolve(true); + } else { + reject(res.data?.msg || "登录失败"); + } + } catch (err) { + reject("网络异常"); + } + }, + fail: () => reject("登录授权失败") + }); + }); +}; + +// 只创建一次Vue实例(删除重复声明) +const app = new Vue({ + ...App, + store +}) + app.$mount() \ No newline at end of file diff --git a/manifest.json b/manifest.json index bec6eaf..0c00531 100644 --- a/manifest.json +++ b/manifest.json @@ -1,27 +1,23 @@ { - "name" : "lucky_weapp", - "appid" : "__UNI__A3A4830", - "description" : "", - "versionName" : "1.0.0", - "versionCode" : "100", - "transformPx" : false, - /* 5+App特有相关 */ - "app-plus" : { - "usingComponents" : true, - "nvueCompiler" : "uni-app", - "splashscreen" : { - "alwaysShowBeforeRender" : true, - "waiting" : true, - "autoclose" : true, - "delay" : 0 + "name":"lucky_weapp", + "appid":"__UNI__A3A4830", + "description":"", + "versionName":"1.0.0", + "versionCode":"100", + "transformPx":false, + "app-plus":{ + "usingComponents":true, + "nvueCompiler":"uni-app", + "splashscreen":{ + "alwaysShowBeforeRender":true, + "waiting":true, + "autoclose":true, + "delay":0 }, - /* 模块配置 */ - "modules" : {}, - /* 应用发布信息 */ - "distribute" : { - /* android打包配置 */ - "android" : { - "permissions" : [ + "modules":{}, + "distribute":{ + "android":{ + "permissions":[ "", "", "", @@ -46,90 +42,164 @@ "" ] }, - /* ios打包配置 */ - "ios" : {}, - /* SDK配置 */ - "sdkConfigs" : { - "ad" : {} + "ios":{}, + "sdkConfigs":{ + "ad":{}, + // App端支付SDK配置(适配原生App支付) + "payment":{ + "weixin":{ + "appid":"wx1234567890abcdef", // 替换:微信开放平台AppID + "universalLink":"https://yourdomain.com/apple-app-site-association" // 替换:iOS微信Universal Link + }, + "alipay":{ + "appid":"2024000000000000" // 替换:支付宝开放平台AppID + }, + "huawei":{ + "appid":"12345678" // 替换:华为开发者联盟AppID(应用市场申请) + } + } } } }, - /* 小程序特有相关 */ - "mp-weixin" : { - "appid" : "wxa8f94045d9c2fc10", - "setting" : { - "urlCheck" : false, - "postcss" : false, - "es6" : true, - "minified" : true + "mp-weixin":{ + "appid":"wxa8f94045d9c2fc10", // 你的微信小程序AppID(已保留) + "setting":{ + "urlCheck":false, + "postcss":false, + "es6":true, + "minified":true }, - "usingComponents" : true, - "permission" : { - "scope.userLocation" : { - "desc" : "为了更好地为您提供服务" + "usingComponents":true, + "permission":{ + "scope.userLocation":{ + "desc":"为了更好地为您提供服务" }, - "scope.writePhotosAlbum" : { - "desc" : "为了更好地为您提供服务" + "scope.writePhotosAlbum":{ + "desc":"为了更好地为您提供服务" } }, - "requiredPrivateInfos" : [ "chooseLocation", "getLocation", "chooseAddress" ], - "__usePrivacyCheck__" : true, - "optimization" : { - "subPackages" : true + "useDeprecatedAPI":{ + "getSystemInfoSync":false + }, + "requiredPrivateInfos":["chooseLocation","getLocation","chooseAddress"], + "__usePrivacyCheck__":true, + "optimization":{ + "subPackages":true + }, + // 微信小程序支付核心配置(官方规范) + "pay":{ + "merchantId":"1688888888", // 替换:你的微信支付商户号(商户平台获取) + "keyPath":"cert/apiclient_key.p12" // 可选:微信支付证书路径(退款/分账等接口需用) + }, + "sdkConfigs":{ + "jssdk":{ + "apis":["chooseWXPay"] // 必须:开启微信JSSDK支付接口(H5/小程序共用) + } } }, - "mp-alipay" : { - "usingComponents" : true, - "appid" : "" + "mp-alipay":{ + "usingComponents":true, + "appid":"2024000000000000", // 替换:你的支付宝小程序AppID(开放平台获取) + // 支付宝小程序支付配置(官方规范) + "pay":{ + "merchantId":"2088888888888888" // 替换:你的支付宝支付商户号 + } }, - "mp-baidu" : { - "usingComponents" : true + "mp-baidu":{ + "usingComponents":true }, - "mp-toutiao" : { - "usingComponents" : true + "mp-toutiao":{ + "usingComponents":true }, - "h5" : { - "sdkConfigs" : { - "maps" : { - "qqmap" : { - "key" : "TUHBZ-CNWKU-UHAVP-GZQ26-HNZFO-3YBF4" + "h5":{ + "sdkConfigs":{ + "maps":{ + "qqmap":{ + "key":"TUHBZ-CNWKU-UHAVP-GZQ26-HNZFO-3YBF4" // 已保留 + }, + // H5端微信/华为支付JSSDK配置 + "weixin":{ + "appid":"wxa8f94045d9c2fc10" // 和微信小程序AppID一致(无需修改) + }, + "huawei":{ + "appid":"12345678" // 替换:华为开发者联盟AppID } } }, - "router" : { - "mode" : "history", - "base" : "/hwapp/" + "router":{ + "mode":"hash", // 必须:hash模式适配支付回调跳转 + "base":"/hwapp/" }, - "title" : " ", - "devServer" : { - "https" : false - }, - "optimization" : { - "treeShaking" : { - "enable" : false + "title":"华为支付演示", + "devServer":{ + "https":false, + // H5端支付接口跨域代理(解决浏览器跨域限制) + "proxy":{ + // 华为支付接口代理 + "/api/huawei":{ + "target":"https://iap-api.cloud.huawei.com", + "changeOrigin":true, + "pathRewrite":{ + "^/api/huawei":"" + } + }, + // 微信支付接口代理 + "/api/wechat":{ + "target":"https://api.mch.weixin.qq.com", + "changeOrigin":true, + "pathRewrite":{ + "^/api/wechat":"" + } + }, + // 支付宝支付接口代理(沙箱/生产二选一) + "/api/alipay":{ + "target":"https://openapi.alipaydev.com", // 沙箱环境;生产:https://openapi.alipay.com + "changeOrigin":true, + "pathRewrite":{ + "^/api/alipay":"" + } + } } }, - "domain" : " ", - "unipush" : { - "enable" : false + "optimization":{ + "treeShaking":{ + "enable":false + } }, - "async" : { - "loading" : "", - "error" : "", - "delay" : 0, - "timeout" : 3000 + "domain":" ", + "unipush":{ + "enable":false }, - "template" : "" + "async":{ + "loading":"", + "error":"", + "delay":0, + "timeout":3000 + }, + "template":"" }, - "uniStatistics" : { - "version" : "2" + "uniStatistics":{ + "version":"2" }, - "sassImplementationName" : "node-sass", - /** 快应用配置 **/ - "quickapp-webview" : { - "package" : "com.jieganfsj.fivegshop", - "minPlatformVersion" : 1070, - "versionName" : "1.0.0", - "versionCode" : 0 + "sassImplementationName":"node-sass", + "quickapp-webview":{ + "package":"com.jieganfsj.fivegshop", // 已保留:华为快应用包名 + "minPlatformVersion":1070, + "versionName":"1.0.0", + "versionCode":0, + // 华为快应用支付核心配置(官方规范) + "sdkConfigs":{ + "huawei":{ + "appid":"12345678", // 替换:华为开发者联盟AppID + "payment":{ + "merchantId":"88888888" // 替换:华为支付商户号(商户平台获取) + } + } + }, + // 华为快应用必须声明的支付权限(官方强制) + "features":[ + {"name":"system.pay"}, + {"name":"huawei.pay"} + ] } -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f43ba2b..9762499 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,14 @@ { - "name": "frontend", + "name": "lucky_shop", "lockfileVersion": 2, "requires": true, "packages": { "": { "dependencies": { "@dcloudio/uni-quickapp-webview": "^2.0.2-4080420251103001", + "crypto-js": "^4.1.1", + "js-base64": "^3.7.2", + "jsencrypt": "^3.2.1", "jweixin-module": "^1.6.0" }, "devDependencies": { @@ -455,6 +458,12 @@ "dev": true, "license": "MIT" }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==", + "license": "MIT" + }, "node_modules/electron-to-chromium": { "version": "1.5.4", "resolved": "https://repo.huaweicloud.com/repository/npm/electron-to-chromium/-/electron-to-chromium-1.5.4.tgz", @@ -614,6 +623,18 @@ "node": ">= 10.13.0" } }, + "node_modules/js-base64": { + "version": "3.7.8", + "resolved": "https://registry.npmmirror.com/js-base64/-/js-base64-3.7.8.tgz", + "integrity": "sha512-hNngCeKxIUQiEUN3GPJOkz4wF/YvdUdbNL9hsBcMQTkKzboD7T/q3OYOuuPZLUE6dBxSGpwhk5mwuDud7JVAow==", + "license": "BSD-3-Clause" + }, + "node_modules/jsencrypt": { + "version": "3.5.4", + "resolved": "https://registry.npmmirror.com/jsencrypt/-/jsencrypt-3.5.4.tgz", + "integrity": "sha512-kNjfYEMNASxrDGsmcSQh/rUTmcoRfSUkxnAz+MMywM8jtGu+fFEZ3nJjHM58zscVnwR0fYmG9sGkTDjqUdpiwA==", + "license": "MIT" + }, "node_modules/json-parse-even-better-errors": { "version": "2.3.1", "resolved": "https://repo.huaweicloud.com/repository/npm/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", @@ -1345,6 +1366,11 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, + "crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "electron-to-chromium": { "version": "1.5.4", "resolved": "https://repo.huaweicloud.com/repository/npm/electron-to-chromium/-/electron-to-chromium-1.5.4.tgz", @@ -1464,6 +1490,16 @@ "supports-color": "^8.0.0" } }, + "js-base64": { + "version": "3.7.8", + "resolved": "https://registry.npmmirror.com/js-base64/-/js-base64-3.7.8.tgz", + "integrity": "sha512-hNngCeKxIUQiEUN3GPJOkz4wF/YvdUdbNL9hsBcMQTkKzboD7T/q3OYOuuPZLUE6dBxSGpwhk5mwuDud7JVAow==" + }, + "jsencrypt": { + "version": "3.5.4", + "resolved": "https://registry.npmmirror.com/jsencrypt/-/jsencrypt-3.5.4.tgz", + "integrity": "sha512-kNjfYEMNASxrDGsmcSQh/rUTmcoRfSUkxnAz+MMywM8jtGu+fFEZ3nJjHM58zscVnwR0fYmG9sGkTDjqUdpiwA==" + }, "json-parse-even-better-errors": { "version": "2.3.1", "resolved": "https://repo.huaweicloud.com/repository/npm/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", diff --git a/package.json b/package.json index dbca309..46c12fb 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ }, "dependencies": { "@dcloudio/uni-quickapp-webview": "^2.0.2-4080420251103001", - "jweixin-module": "^1.6.0" + "jweixin-module": "^1.6.0", + "js-base64": "^3.7.2", + "jsencrypt": "^3.2.1", + "crypto-js": "^4.1.1" } -} +} \ No newline at end of file