Browse Source

配置wxappid

空白格 2 years ago
parent
commit
b2b2ecb78b
11 changed files with 62 additions and 561 deletions
  1. 1 1
      .gitignore
  2. 17 9
      README.md
  3. 15 4
      common/config.js
  4. 0 1
      js_sdk/jweixin-1.4.0.js
  5. 0 96
      js_sdk/ms-openMap/openMap.js
  6. 0 126
      js_sdk/ms-openMap/transformCoordinate.js
  7. 0 7
      main.js
  8. 28 4
      package.json
  9. 0 126
      pay.js
  10. 1 1
      static/html/wxPayCallback.html
  11. 0 186
      wxapi.js

+ 1 - 1
.gitignore

@@ -13,6 +13,6 @@ yarn-error.log*
 *.ntvs*
 *.njsproj
 *.sln
-node_modules/
 /package-lock.json
 /.history/
+/node_modules/

+ 17 - 9
README.md

@@ -1,10 +1,18 @@
 ## 城市智慧停车
-### 打包需要修改
-- `common/http.interceptor.js` 中登录链接
-- `common/config.js` 配置信息
-#### iconfont
-- [iconfont 自定义图标](https://www.uviewui.com/guide/customIcon.html)
-- [字体默认不再生成 .eot、.svg 和 Base64](https://github.com/thx/iconfont-plus/issues/1948)
-
-#### 安装vue-jsonp
-`npm install vue-jsonp --save`
+
+### 修改访问地址
+- 如果api地址有变动 修改package.json 中的环境变量配置
+- common/config.js 本地运行地址修改
+- 项目中的点金计划页面修改static/html/wxPayCallback.html中(jumpOutUrl)修改为需要跳转的页面
+
+### 打包
+- 打包测试环境: 发行 => 自定义发行 => build:test
+- 打包正式环境: 发行 => 自定义发行 => build:pro
+
+### 执行 `npm install`
+
+#### 安装vue-jsonp 获取地址数据跨域处理
+`npm install vue-jsonp --save`
+
+#### 安装weixin-js-sdk 微信支付
+`npm install weixin-js-sdk --save`

+ 15 - 4
common/config.js

@@ -1,8 +1,19 @@
+/**
+ * 在package.json中定义的H_NODE_ENV
+ * 在本地运行该环境为未定义,设置初始baseUrl
+ * 只有在打包环境下才会有H_NODE_ENV
+ */
+const node_dev = process.env.H_NODE_ENV
+let baseUrl = 'https://wx.hw.hongweisoft.com/parking',
+wxAppid = 'wx6e9cdf7a0ee8a51b'
+console.log(process.env.H_BASE_URL);
+if (node_dev) {
+	baseUrl = process.env.H_BASE_URL,
+	wxAppid = process.env.H_WXAPPID
+}
 const config = {
-	// wxAppid: 'wx45c3cf2b632f5fd5', // 正式wxAppid
-	wxAppid: 'wx6e9cdf7a0ee8a51b', // 达泽wxAppid
-	baseUrl:'https://wx.hw.hongweisoft.com/parking',// 64服务器
-	// baseUrl: 'https://parking.pdzhtc.com', //正式接口访问地址
+	wxAppid,
+	baseUrl
 }
 export {
 	config

File diff suppressed because it is too large
+ 0 - 1
js_sdk/jweixin-1.4.0.js


+ 0 - 96
js_sdk/ms-openMap/openMap.js

@@ -1,96 +0,0 @@
-import TransformCoordinate from './transformCoordinate.js'
-function openMapByDefault(latitude, longitude, name) {
-	uni.openLocation({
-		latitude: latitude,
-		longitude: longitude,
-		name: name,
-		fail: () => {
-			uni.showModal({
-				content: '打开地图失败,请重'
-			})
-		},
-	})
-}
-function openMapByAndroid(latitude, longitude, name) {
-	let url = ''; // 回调地址
-	let identity = ''; // 程序名称
-	if(plus.runtime.isApplicationExist({pname: 'com.baidu.BaiduMap'})) { // baidumap
-		url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`
-		identity = 'com.baidu.BaiduMap'
-		openURL(url, identity)
-	}
-	else if(plus.runtime.isApplicationExist({pname: 'com.autonavi.minimap'})) { // 高德
-		url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`
-		identity = 'com.autonavi.minimap'
-		openURL(url, identity)
-	}
-	else {
-		openMapByDefault(latitude, longitude, name)
-	}
-}
-function openMapByIos(latitude, longitude, name) {
-	let url = ''; // 回调地址
-	let errorCB = ''; // url失败的回调地址
-	let identity = ''; // 程序名称
-
-	if(plus.runtime.isApplicationExist({action: 'baidumap://'})) { // baidumap
-		url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
-		openURL(url, identity)
-	}
-	else if(plus.runtime.isApplicationExist({action: 'iosamap://'})) { // 高德
-		url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`
-		openURL(url, identity)
-	} 
-	else {
-		openMapByDefault(latitude, longitude, name)
-	}
-}
-function openURL(url, identity ) {
-	let newurl = encodeURI(url);
-	plus.runtime.openURL( newurl, function(res){
-		uni.showModal({
-			content: res.message
-		})
-	}, identity);
-}
-function getCoordByType(longitude, latitude, coord_type) {
-	switch (coord_type){
-		case 'gcj02':
-			return [longitude, latitude]
-			break;
-		case 'bd09':
-			return TransformCoordinate.bd09togcj02(longitude, latitude)
-			break;
-		case 'wgs84':
-			return TransformCoordinate.wgs84togcj02(longitude, latitude)
-			break;
-		default:
-			return [longitude, latitude]
-			break;
-	}
-}
-export default {
-	/* 打开地图 */
-	openMap(latitude, longitude, name, coord_type='gcj02') {
-		let arr = getCoordByType(longitude, latitude, coord_type)
-		// #ifdef APP-PLUS
-		switch(uni.getSystemInfoSync().platform){
-			case 'android':
-				console.log('运行Android上')
-				openMapByAndroid(arr[1], arr[0], name)
-				break;
-			case 'ios':
-				console.log('运行iOS上')
-				openMapByIos(arr[1], arr[0], name)
-				break;
-			default:
-				openMapByDefault(arr[1], arr[0], name)
-				console.log('运行在开发者工具上')	
-				break;
-		}	
-		// #endif
-		// #ifndef APP-PLUS
-		openMapByDefault(arr[1], arr[0], name)
-		// #endif
-	}
-}

+ 0 - 126
js_sdk/ms-openMap/transformCoordinate.js

@@ -1,126 +0,0 @@
-/**
- * Created by Wandergis on 2015/7/8.
- * 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
- */
- 
-//定义一些常量
-var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
-var PI = 3.1415926535897932384626;
-var a = 6378245.0;
-var ee = 0.00669342162296594323;
- 
-/**
- * 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
- * 即 百度 转 谷歌、高德
- * @param bd_lon
- * @param bd_lat
- * @returns {*[]}
- */
-function bd09togcj02(bd_lon, bd_lat) {
-    var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
-    var x = bd_lon - 0.0065;
-    var y = bd_lat - 0.006;
-    var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
-    var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
-    var gg_lng = z * Math.cos(theta);
-    var gg_lat = z * Math.sin(theta);
-    return [gg_lng, gg_lat]
-}
- 
-/**
- * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
- * 即谷歌、高德 转 百度
- * @param lng
- * @param lat
- * @returns {*[]}
- */
-function gcj02tobd09(lng, lat) {
-    var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
-    var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
-    var bd_lng = z * Math.cos(theta) + 0.0065;
-    var bd_lat = z * Math.sin(theta) + 0.006;
-    return [bd_lng, bd_lat]
-}
- 
-/**
- * WGS84转GCj02
- * @param lng
- * @param lat
- * @returns {*[]}
- */
-function wgs84togcj02(lng, lat) {
-    if (out_of_china(lng, lat)) {
-        return [lng, lat]
-    }
-    else {
-        var dlat = transformlat(lng - 105.0, lat - 35.0);
-        var dlng = transformlng(lng - 105.0, lat - 35.0);
-        var radlat = lat / 180.0 * PI;
-        var magic = Math.sin(radlat);
-        magic = 1 - ee * magic * magic;
-        var sqrtmagic = Math.sqrt(magic);
-        dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
-        dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
-        var mglat = lat + dlat;
-        var mglng = lng + dlng;
-        return [mglng, mglat]
-    }
-}
- 
-/**
- * GCJ02 转换为 WGS84
- * @param lng
- * @param lat
- * @returns {*[]}
- */
-function gcj02towgs84(lng, lat) {
-    if (out_of_china(lng, lat)) {
-        return [lng, lat]
-    }
-    else {
-        var dlat = transformlat(lng - 105.0, lat - 35.0);
-        var dlng = transformlng(lng - 105.0, lat - 35.0);
-        var radlat = lat / 180.0 * PI;
-        var magic = Math.sin(radlat);
-        magic = 1 - ee * magic * magic;
-        var sqrtmagic = Math.sqrt(magic);
-        dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
-        dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
-        mglat = lat + dlat;
-        mglng = lng + dlng;
-        return [lng * 2 - mglng, lat * 2 - mglat]
-    }
-}
- 
-function transformlat(lng, lat) {
-    var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
-    ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
-    ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
-    ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
-    return ret
-}
- 
-function transformlng(lng, lat) {
-    var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
-    ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
-    ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
-    ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
-    return ret
-}
- 
-/**
- * 判断是否在国内,不在国内则不做偏移
- * @param lng
- * @param lat
- * @returns {boolean}
- */
-function out_of_china(lng, lat) {
-    return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false);
-}
-
-export default {
-	bd09togcj02: bd09togcj02,  // 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
-	gcj02tobd09: gcj02tobd09, // 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
-	wgs84togcj02: wgs84togcj02,  // 
-	gcj02towgs84: gcj02towgs84,
-}

+ 0 - 7
main.js

@@ -20,13 +20,6 @@ import store from '@/store';
 let vuexStore = require('@/store/$u.mixin.js');
 Vue.mixin(vuexStore);
 
-import $wxApi from "./wxapi.js";
-Vue.prototype.$wxApi = $wxApi;
-
-//微信支付封装
-import $pay from "./pay.js";
-Vue.prototype.$pay = $pay
-
 const app = new Vue({
 	store,
     ...App

+ 28 - 4
package.json

@@ -1,6 +1,30 @@
 {
-  "dependencies": {
-    "vue-jsonp": "^2.0.0",
-    "weixin-js-sdk": "^1.6.0"
-  }
+	"uni-app": {
+		"scripts": {
+			"build:test": {
+				"title": "build:test",
+				"env": {
+					"UNI_PLATFORM": "h5",
+					"H_NODE_ENV": "development",
+					"H_BASE_URL": "https://wx.hw.hongweisoft.com/parking",
+					"H_WXAPPID": "wx6e9cdf7a0ee8a51b",
+					"DESCRIBE": "测试环境"
+				}
+			},
+			"build:pro": {
+				"title": "build:pro",
+				"env": {
+					"UNI_PLATFORM": "h5",
+					"H_NODE_ENV": "production",
+					"H_BASE_URL": "https://parking.pdzhtc.com",
+					"H_WXAPPID": "wx45c3cf2b632f5fd5",
+					"DESCRIBE": "正式环境"
+				}
+			}
+		}
+	},
+	"dependencies": {
+		"vue-jsonp": "^2.0.0",
+		"weixin-js-sdk": "^1.6.0"
+	}
 }

+ 0 - 126
pay.js

@@ -1,126 +0,0 @@
-/**
- * 订单支付
- */
-import Vue from "vue";
-//#ifdef H5
-import $wxApi from "./wxapi.js";
-//#endif
-
-// import $http from "./utils/axios.js"
-import $http from "./uview-ui/libs/request"
-
-export default {
-	//微信支付
-	// wxPay(obj = {}) {
-	// 	uni.showLoading({
-	// 		title: '支付中'
-	// 	});
-	// 	return new Promise(r => {
-	// 		$http.post("/client/wechat/pay",obj)
-	// 			.then(res=>{
-	// 				//#ifdef H5
-	// 				$wxApi.JSAPI(res.data).then(r);
-	// 				//#endif
-	// 				this.payError(res);
-	// 			}).catch(err =>{
-	// 				// alert(err.msg);
-	// 				console.log('pay err',err);
-	// 			})
-	// 	});
-	// },
-	// 微信支付
-	wxPay(obj = {}, url = '/client/pay/wechat', jumpUrl) {
-		uni.showLoading({
-			title: '支付中'
-		});
-		return new Promise(r => {
-			$http.post(url, obj)
-				.then(res => {
-					// 区分包月支付和普通支付
-					if (res.data.needPay && !res.data.monthId) {
-						//#ifdef H5
-						$wxApi.JSAPI(res.data.wx, jumpUrl).then(r);
-						//#endif
-					} else if (res.data.monthId) {
-						//#ifdef H5
-						$wxApi.JSAPI(res.data.wx, jumpUrl).then(r);
-						//#endif
-					} else {
-						uni.showToast({
-							title: "无需支付",
-							icon: "none",
-							duration: 2000
-						});
-						setTimeout(() => {
-							//#ifdef H5
-							if (jumpUrl) {
-								window.location.href = jumpUrl;
-							} else {
-								window.location.reload();
-							}
-							//#endif
-						}, 1500)
-					}
-				})
-		});
-	},
-	/**
-	 * 微信支付
-	 * obj 传入对象
-	 * url 提交地址
-	 * jumpUrl 支付成功跳转 
-	 */
-	wechatPay(obj = {}, url = '/client/pay/wechat', jumpUrl) {
-		uni.showLoading({
-			title: '支付中'
-		});
-		return new Promise(r => {
-			$http.post(url, obj)
-				.then(res => {
-					// 区分包月支付和普通支付
-					if (res.data.needPay && !res.data.monthId) {
-						//#ifdef H5
-						$wxApi.JSAPI(res.data.wx, jumpUrl).then(r);
-						//#endif
-					} else if (res.data.monthId) {
-						//#ifdef H5
-						$wxApi.JSAPI(res.data.wx, jumpUrl).then(r);
-						//#endif
-					} else {
-						uni.showToast({
-							title: "无需支付",
-							icon: "none",
-							duration: 2000
-						});
-						setTimeout(() => {
-							//#ifdef H5
-							if (jumpUrl) {
-								window.location.href = jumpUrl;
-							} else {
-								window.location.reload();
-							}
-							//#endif
-						}, 1500)
-					}
-					this.payError(res);
-				}).catch(err => {
-					// alert(err.msg);
-					console.log('pay err', err);
-				})
-		});
-	},
-	//支付错误处理
-	payError(res) {
-		uni.hideLoading();
-		if (res.code == 623) {
-			setTimeout(i => {
-				new Vue().$api.goto("/pages/userCenter/myOrder/myOrder");
-			}, 2000);
-			uni.showToast({
-				title: res.msg + "    即将跳转到订单页",
-				icon: "none",
-				duration: 2000
-			});
-		}
-	}
-}

+ 1 - 1
static/html/wxPayCallback.html

@@ -82,7 +82,7 @@
         let mchData ={action:'onIframeReady',displayStyle:'SHOW_CUSTOM_PAGE',
                                height:960};//高度可选(参考说明文档)
         var postData = JSON.stringify(mchData);
-        parent.postMessage(postData,'https://payapp.weixin.qq.com');
+        parent.postMessage(postData, 'https://payapp.weixin.qq.com');
         
         const jumpUrl = localStorage.getItem('jumpUrl')
         //测试跳转到其他页面【非必需】

+ 0 - 186
wxapi.js

@@ -1,186 +0,0 @@
-//引入微信jssdk
-const wx = require('@/js_sdk/jweixin-1.4.0.js')
-
-//配置注册url
-const url = '/client/wechat/pay/getJsapiTicket';
-
-//http方法
-// import $http from './utils/axios.js'
-import $http from "./uview-ui/libs/request"
-
-//系统域名url
-const href = location.href.split('#')[0];
-// const href = location.href.split("?")[0]
-
-import {
-	config
-} from '@/common/config'
-
-//系统域名url
-export default {
-	...wx,
-	isOk: false,
-	async config() {
-		wx.config({
-			debug: false,
-			jsApiList: [
-				"updateAppMessageShareData",
-				"updateTimelineShareData",
-				"onMenuShareTimeline",
-				"onMenuShareAppMessage",
-				"onMenuShareQQ",
-				"onMenuShareWeibo",
-				"onMenuShareQZone",
-				"startRecord",
-				"stopRecord",
-				"onVoiceRecordEnd",
-				"playVoice",
-				"pauseVoice",
-				"stopVoice",
-				"onVoicePlayEnd",
-				"uploadVoice",
-				"downloadVoice",
-				"chooseImage",
-				"previewImage",
-				"uploadImage",
-				"downloadImage",
-				"translateVoice",
-				"getNetworkType",
-				"openLocation",
-				"getLocation",
-				"hideOptionMenu",
-				"showOptionMenu",
-				"hideMenuItems",
-				"showMenuItems",
-				"hideAllNonBaseMenuItem",
-				"showAllNonBaseMenuItem",
-				"closeWindow",
-				"scanQRCode",
-				"chooseWXPay",
-				"openProductSpecificView",
-				"addCard",
-				"chooseCard",
-				"openCard"
-			],
-			...(await $http.get(url, {
-				url: href
-			})).data,
-			// ...(await uni.request(url,{url:href})).retBody,
-		});
-		wx.ready(e => {
-			this.isOk = true;
-			// this.hideMenu();
-		});
-		wx.error(e => {
-			console.log("wxapi初始化失败")
-			this.isOk = false;
-		});
-	},
-	hideMenu() {
-		wx.hideAllNonBaseMenuItem();
-		wx.hideMenuItems({
-			menuList: [
-				"menuItem:share:appMessage",
-				"menuItem:profile",
-				"menuItem:addContact",
-				"menuItem:dayMode",
-				"menuItem:nightMode",
-				"menuItem:share:timeline",
-				"menuItem:favorite"
-			] // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3		
-		});
-	},
-	showMenu() {
-		wx.showMenuItems({
-			menuList: [
-				"menuItem:share:appMessage",
-				"menuItem:profile",
-				"menuItem:addContact",
-				"menuItem:dayMode",
-				"menuItem:nightMode",
-				"menuItem:share:timeline",
-				"menuItem:favorite"
-			] // 要显示的菜单项,所有menu项见附录3
-		});
-	},
-	/**
-	 * 分享配置
-	 * @param {Object} info
-	 */
-	share(data = {}, info = {}) {
-		//添加链接时间戳
-		// data.v = new Date().getTime();
-		// console.log("shareData",data)
-		// let search = [];
-		// for (const [key, value] of Object.entries(data)) {
-		// 	// search.push(`${key}=${encodeURIComponent(value)}`);
-		// 	search.push(`${key}=${value}`);
-		// }
-		// search = "?" + search.join("&");
-
-		let afterEndUrl = config.afterEndUrl;
-		// let afterEndUrl = 'http://tanhui.hongweisoft.com/api/wechat/h5/authorize?returnUrl='
-		// let afterEndUrl = 'http://gzhjt.gzsdzth.com/api/wechat/h5/authorize?returnUrl='
-
-		let fullUrl = afterEndUrl + location.href.split('?')[0] + '?togetherId=' + data.togetherId + '/#/' + data
-			.routeUrl
-		const shareInfo = {
-			title: data.nickname + '邀请你参与贵州省单株碳汇精准扶贫',
-			link: fullUrl,
-			desc: "购碳扶贫,你我同行",
-			imgUrl: href + "/static/logo.png",
-			trigger(res) {},
-			success(res) {},
-			cancel(res) {},
-			fail(res) {},
-			...info
-		};
-		console.log('shareInfo', shareInfo, 'fullUrl', fullUrl)
-		//自定义“分享给朋友”及“分享到QQ”按钮的分享内容(1.4.0)
-		wx.updateAppMessageShareData(shareInfo);
-		//自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容(1.4.0)
-		wx.updateTimelineShareData(shareInfo);
-	},
-	//拉起微信浏览器端支付
-	JSAPI(res, jumpUrl) {
-		return new Promise(r => {
-			wx.chooseWXPay({
-				"appId": res.appId,
-				"timeStamp": res.timeStamp, //时间戳,自1970年以来的秒数     
-				"nonceStr": res.nonceStr, //随机串     
-				"package": res.packageValue,
-				"signType": res.signType, //微信签名方式:     
-				"paySign": res.paySign, //微信签名
-				success(data) {
-					r({
-						code: 0,
-						msg: "成功"
-					});
-				},
-				cancel() {
-					r({
-						code: 1,
-						msg: "取消"
-					});
-				},
-				fail(err) {
-					r({
-						code: 2,
-						msg: err.errMsg.split(':')[1]
-					});
-				},
-				// 无论失败成功都会执行
-				complete(e) {
-					// e.errMsg三种状态 1.chooseWXPay:ok 支付成功 2: chooseWXPay:cancel 支付取消 3:chooseWXPay:fail 支付失败
-					if (e.errMsg === 'chooseWXPay:ok') {
-						if (jumpUrl) {
-							window.location.href = jumpUrl
-						} else {
-							window.location.reload()
-						}
-					}
-				}
-			});
-		});
-	}
-}