zizhong.wang hace 2 años
padre
commit
c4ce3564b6
Se han modificado 4 ficheros con 73 adiciones y 24 borrados
  1. 4 4
      App.vue
  2. 1 1
      manifest.json
  3. 67 18
      pages/heatingPage/pay.vue
  4. 1 1
      project.config.json

+ 4 - 4
App.vue

@@ -2,15 +2,15 @@
 import md5 from '@/common/md5.js';
 export default {
   globalData: {
-    shareUrl: "https://heater.xazhima.com/",
-	//shareUrl:"https://kgwxxcx.xixianxinqu.gov.cn/1026airqt/",
+    //shareUrl: "https://heater.xazhima.com/", 测试地址
+	shareUrl:"https://h.xayuanju.com/",
     globalTimestamp: Date.now().toString(),
     secret: "Heater_weichat_app_zhima",
     selectedIndex:0,
 	isSider:false,
 	user_id: '',
-	//open_id:'',
-	open_id:"oX46e5ImwFndnH442HW6Yt7W9Mck",//测试使用 替换正确appId后默认为空
+	open_id:'',
+	//open_id:"oX46e5ImwFndnH442HW6Yt7W9Mck",//测试使用 替换正确appId后默认为空
 	user_status:'',
 	user_name:'',
 	user_phone:'',

+ 1 - 1
manifest.json

@@ -60,7 +60,7 @@
     "quickapp" : {},
     /* 小程序特有相关 */
     "mp-weixin" : {
-        "appid" : "wx1dbc76c97a3e4880",
+        "appid" : "wx3cf5d0fd376116e2",
         "setting" : {
             "urlCheck" : false,
             "minified" : true,

+ 67 - 18
pages/heatingPage/pay.vue

@@ -64,10 +64,12 @@ export default {
       payInfo: {
       },
 	  payStatus:0,
+	  pay_code : '',
     };
   },
   onLoad(option) {
-	this.getPayDetail(option.id)
+	this.getPayDetail(option.id);
+	this.pay_code = option.id;
   },
   methods: {   
     getPayDetail(payId) {
@@ -87,7 +89,7 @@ export default {
         "&sign=" +
         md5Sign;
       let postData = {
-        code:payId, 
+        code:payId,
         openId: getApp().globalData.open_id,
       };
       uni.request({
@@ -126,28 +128,75 @@ export default {
 			let value = this.payInfo.total_fee - this.payInfo.reduction;
 			this.payInfo.real_fee = value;
 		}
-		this.payInfo.payType = e.detail.value;
+		this.payInfo.type = e.detail.value;
 	},
 	paySubmit(){
 		if(this.payStatus){
 			this.open()
 			return
 		}
-		uni.requestPayment({
-			provider: 'wxpay',
-			timeStamp: String(Date.now()),
-			nonceStr: 'A1B2C3D4E5',
-			package: 'prepay_id=wx20180101abcdefg',
-			signType: 'MD5',
-			paySign: '',
-			success: function (res) {
-				console.log('success:' + JSON.stringify(res));
-				this.payStatus = 1;
-			},
-			fail: function (err) {
-				console.log('fail:' + JSON.stringify(err));
-			}
-		});	
+		
+		let md5Sign = md5(
+		  "method=" +
+		    "user" +
+		    "&timestamp=" +
+		    getApp().globalData.globalTimestamp +
+		    "&secret=" +
+		    getApp().globalData.secret
+		);
+		let url =
+		  getApp().globalData.shareUrl +
+		  "api/api.php" +
+		  "?method=user&source=user&action=prepay&timestamp=" +
+		  getApp().globalData.globalTimestamp +
+		  "&sign=" +
+		  md5Sign;
+		let postData = {
+		  code:this.pay_code,
+		  type : this.payInfo.type,
+		  openId: getApp().globalData.open_id,
+		};
+		uni.request({
+		  url: url,
+		  method: "POST",
+		  header: {
+		    "content-type": "application/x-www-form-urlencoded",
+		  },
+		  data: postData,
+		  success: (res) => {
+		    if (res.data.code === 200) {
+		         let r = res.data.data;
+				 uni.requestPayment({
+				 	provider: 'wxpay',
+				 	timeStamp: String(Date.now()),
+				 	nonceStr: r.nonce_str,
+				 	package: 'prepay_id=' + r.prepay_id,
+				 	signType: 'MD5',
+				 	paySign: r.sign,
+				 	success: function (res) {
+				 		console.log('success:' + JSON.stringify(res));
+				 		this.payStatus = 1;
+				 	},
+				 	fail: function (err) {
+				 		console.log('fail:' + JSON.stringify(err));
+				 	}
+				 });
+				 
+				 
+		    } else {
+		      uni.showToast({
+		        title: res.data.msg,
+		        icon: "none",
+		        duration: 2500,
+		      });
+		    }
+		  },
+		  fail: () => {
+		    console.log("连接失败");
+		  },
+		});
+		
+			
 	  //支付这里缺少签名参数 还需要后台配合调用微信那边的接口
 	 //参考https://github.com/dcloudio/H5P.Server/tree/master/payment
 			

+ 1 - 1
project.config.json

@@ -40,7 +40,7 @@
   },
   "compileType": "miniprogram",
   "libVersion": "2.18.0",
-  "appid": "wx889d7d76e7aa3cd3",
+  "appid": "wx3cf5d0fd376116e2",
   "projectname": "miniprogram-1",
   "condition": {},
   "editorSetting": {