| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import common from './util';
- var app = getApp();
- function getData(url, callback) {
- //console.log("加密前的结果为===", url);
- var url = common.Encrypt(url);
- //console.log("加密后的结果为===",url);
- wx.request({
- url: app.globalData.serverUrl + url,
- success: function (res) {
- if (res.statusCode)
- common.checkError(res.statusCode);
- var data = res.data.result;
- callback(data);
- },
- fail: function () {
- wx.redirectTo({
- url: './error',
- });
- },
- });
- }
- function postData(url, postData, callback) {
- var url = common.Encrypt(url);
- //console.log("加密后的结果为===",url);
- wx.request({
- url: app.globalData.serverUrl + url,
- method: "POST",
- data: postData,
- success: function (res) {
- if (res.statusCode)
- common.checkError(res.statusCode);
- var data = res.data.result;
- callback(data);
- },
- fail: function () {
- wx.showToast({
- title: '服务器忙,请稍候再试!',
- duration: 3000
- });
- wx.redirectTo({
- url: './error',
- });
- },
- });
- }
- function getLocalHost(callback) {
- if (!app.globalData.IsProduction) {
- var url = common.Encrypt("Ping");
- wx.request({
- url: app.globalData.serverUrlLocalhost + url,
- success: function (res) {
- app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
- callback();
- },
- fail: function () {
- app.globalData.serverUrl = app.globalData.serverUrlServer;
- callback();
- },
- });
- }
- else {
- app.globalData.serverUrl = app.globalData.serverUrlServer;
- callback();
- }
- }
- function payMoney(payType, money, callback) {
- console.log(money);
- if (app.globalData.userInfo.UserID == 1)
- money = 0.01;
- //登录认证
- wx.login({
- success: function (res) {
- if (res.code) {
- console.log('获取用户登录态成功!' + res.code);
- //预支付
- getData('PhonicsPayLogin?code=' + res.code + '&payType=' + payType + '&money=' + money, function (data) {
- if (data && data.timeStamp) {
- //微信支付
- wx.requestPayment({
- 'timeStamp': data.timeStamp.toString(),
- 'nonceStr': data.nonceStr,
- 'package': data.package,
- 'signType': 'MD5',
- 'paySign': data.paySign,
- 'success': function (res3) {
- app.globalData.userInfo.IsMember = 1;
- app.globalData.userInfo.IsPay = 1;
- console.log("success:" + res3);
- callback();
- },
- 'fail': function (err) {
- if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
- }
- else {
- wx.showToast({
- title: '服务器忙,请稍候再试!',
- duration: 3000
- });
- }
- }
- });
- }
- });
- } else {
- console.log('获取用户登录态失败!' + res.errMsg);
- wx.showToast({
- title: '服务器忙,请稍候再试!',
- duration: 3000
- });
- }
- }
- });
- }
- module.exports = {
- getData: getData,
- postData: postData,
- payMoney: payMoney,
- getLocalHost: getLocalHost,
- }
|