@chuxingpay/junting-sdk
Advanced tools
@@ -11,5 +11,6 @@ | ||
| password: '755fa1281b766e7031057e81363d85dd', | ||
| key: 'D3174CE3' | ||
| key: 'D3174CE3', | ||
| ChannelCode: 'fuxun' | ||
| } | ||
| module.exports = { jtTConfig: juntingTest } |
+0
-1
@@ -101,3 +101,2 @@ const Teambition = require('teambition') | ||
| } | ||
| console.log('qqqqqqqqqqqqqqqqqqqqqqqqq',options) | ||
| debug('sendRequest', options) | ||
@@ -104,0 +103,0 @@ return new Promise((resolve, reject) => { |
+50
-31
@@ -5,6 +5,6 @@ 'use strict' | ||
| const Request = require('./request') | ||
| const md5 = require('md5') | ||
| const moment = require('moment') | ||
| let token | ||
| class JunTingSDK { | ||
| constructor({ authorization, GroupCode, HotelCode, account, password, access_token, key }, env = 'test') { | ||
| constructor({ authorization, GroupCode, HotelCode, account, password, key }, env = 'test') { | ||
| if (!authorization || !GroupCode || !HotelCode || !account || !password ) throw new Error('params error') | ||
@@ -17,7 +17,22 @@ this.authorization = authorization | ||
| this.clientId = GroupCode + '^' + HotelCode + '^' + account + '^' + authorization | ||
| if(access_token) this.access_token = access_token | ||
| this.key = key | ||
| this.request = new Request(env === 'test', '', this.clientId, this.password, this.access_token?this.access_token:null, this.key) | ||
| this.initPromise = null | ||
| } | ||
| async initReuqest() { | ||
| if (this.initPromise) { | ||
| return this.initPromise | ||
| } | ||
| this.initPromise = new Promise( async (resolve) => { | ||
| await JunTingSDK.getToken(this.clientId, this.password) | ||
| this.request = new Request(true, '', this.clientId, this.password, token, this.key) | ||
| setTimeout(() => { | ||
| this.initReuqest() | ||
| }, 23 * 3600000) | ||
| resolve(true) | ||
| }) | ||
| return this.initPromise | ||
| } | ||
| /** | ||
@@ -28,9 +43,13 @@ * 获取访问令牌 | ||
| */ | ||
| async getToken(clientId, password) { | ||
| const data = await new Request().get(`http://112.17.72.71:8350/api/OAuth2/GetToken?clientId=${clientId}&clientSecret=${password}`) | ||
| if (data.Code === 0) { | ||
| return data.Data.access_token | ||
| } else { | ||
| this.getToken() | ||
| static async getToken(clientId, password) { | ||
| const data = await new Request().get( | ||
| `http://112.17.72.71:8350/api/OAuth2/GetToken?clientId=${clientId}&clientSecret=${password}`, | ||
| { maxAttempts: 5, retryDelay: 1000 } | ||
| ) | ||
| if (!data || data.Code !== 0) { | ||
| debug('Unsupport Result : ', data) | ||
| throw new Error('GetTokenError') | ||
| } | ||
| token = data.Data.access_token | ||
| } | ||
@@ -109,3 +128,3 @@ | ||
| */ | ||
| async getHotelRoomTypeList(GroupCode, HotelCode) { | ||
| async getHotelRoomTypeList(GroupCode, HotelCode, ChannelCode) { | ||
| if (!GroupCode) throw new Error('GroupCode is required') | ||
@@ -115,2 +134,3 @@ if (!HotelCode) throw new Error('HotelCode is required') | ||
| const query = { | ||
| ChannelCode: ChannelCode, | ||
| Status: '', | ||
@@ -137,3 +157,3 @@ Id: 0, | ||
| */ | ||
| async getRoomTypeInfo(GroupCode, HotelCode, RoomType) { | ||
| async getRoomTypeInfo(GroupCode, HotelCode, RoomType, ChannelCode) { | ||
| if (!GroupCode) throw new Error('GroupCode is required') | ||
@@ -144,2 +164,3 @@ if (!HotelCode) throw new Error('HotelCode is required') | ||
| const query = { | ||
| ChannelCode: ChannelCode, | ||
| HotelFullName: '', | ||
@@ -173,3 +194,2 @@ HotelCity: '', | ||
| if (!RoomType) throw new Error('RoomType is required') | ||
| if (!RateCode) throw new Error('RateCode is required') | ||
| if (!ChannelCode) throw new Error('ChannelCode is required') | ||
@@ -179,6 +199,6 @@ const uri = '/Cms/GetDailyRoomPriceList' | ||
| ChannelCode: ChannelCode, | ||
| StartDate: StartDate ? StartDate : '2000-01-01T00:00:00.00Z', | ||
| EndDate: EndDate ? EndDate : '2222-01-01T00:00:00.000Z', | ||
| StartDate: StartDate ? StartDate : moment().startOf('day').add(0, 'days').format('YYYY-MM-DD'), | ||
| EndDate: EndDate ? EndDate : moment().startOf('day').add(89, 'days').format('YYYY-MM-DD'), | ||
| RoomType: RoomType, | ||
| RateCode: RateCode, | ||
| RateCode: RateCode?RateCode:'', | ||
| Id: 0, | ||
@@ -215,4 +235,4 @@ GroupCode: GroupCode, | ||
| ChannelCode: ChannelCode, | ||
| StartDate: StartDate ? StartDate : '2000-01-01T00:00:00.00Z', | ||
| EndDate: EndDate ? EndDate : '2222-01-01T00:00:00.000Z', | ||
| StartDate: StartDate ? StartDate : moment().startOf('day').add(0, 'days').format('YYYY-MM-DD'), | ||
| EndDate: EndDate ? EndDate : moment().startOf('day').add(89, 'days').format('YYYY-MM-DD'), | ||
| RoomType: RoomType, | ||
@@ -247,3 +267,2 @@ RateCode: RateCode, | ||
| if (!RoomType) throw new Error('RoomType is required') | ||
| if (!RateCode) throw new Error('RateCode is required') | ||
| if (!ChannelCode) throw new Error('ChannelCode is required') | ||
@@ -253,13 +272,13 @@ const uri = '/Cms/GetRoomStockList' | ||
| ChannelCode: ChannelCode, | ||
| StartDate: StartDate ? StartDate : '2000-01-01T00:00:00.00Z', | ||
| EndDate: EndDate ? EndDate : '2222-01-01T00:00:00.000Z', | ||
| StartDate: StartDate ? StartDate : '2020-03-18T09:31:07.305Z', | ||
| EndDate: EndDate ? EndDate : '2020-03-19T09:31:07.305Z', | ||
| RoomType: RoomType, | ||
| RateCode: RateCode, | ||
| Id: 0, | ||
| RateCode: RateCode?RateCode:'', | ||
| //Id: 0, | ||
| GroupCode: GroupCode, | ||
| HotelCode: HotelCode, | ||
| AscFields: '', | ||
| DescFields: '', | ||
| pageIndex: 0, | ||
| pageSize: 100 | ||
| //AscFields: '', | ||
| //DescFields: '', | ||
| //pageIndex: 0, | ||
| //pageSize: 100 | ||
| } | ||
@@ -473,4 +492,4 @@ return this.request.post(uri, query) | ||
| ChannelCode: ChannelCode, | ||
| StartDate: StartDate ? StartDate : '2000-01-01T00:00:00.00Z', | ||
| EndDate: EndDate ? EndDate : '2222-01-01T00:00:00.000Z', | ||
| StartDate: StartDate ? StartDate : moment().startOf('day').add(0, 'days').format('YYYY-MM-DD'), | ||
| EndDate: EndDate ? EndDate : moment().startOf('day').add(1, 'days').format('YYYY-MM-DD'), | ||
| RoomType: RoomType, | ||
@@ -480,3 +499,3 @@ RoomQuantity: RoomQuantity, | ||
| ComCardNo: ComCardNo ? ComCardNo : '', | ||
| Id: Id ? Id : 0, | ||
| //Id: Id ? Id : 0, | ||
| GroupCode: GroupCode, | ||
@@ -487,3 +506,3 @@ HotelCode: HotelCode, | ||
| pageIndex: 0, | ||
| pageSize: 100 | ||
| pageSize: 0 | ||
| } | ||
@@ -490,0 +509,0 @@ return this.request.post(uri, query) |
+2
-1
| { | ||
| "name": "@chuxingpay/junting-sdk", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "", | ||
@@ -28,2 +28,3 @@ "author": "anxing <chuanxing.huang@chuxingpay.com>", | ||
| "dependencies": { | ||
| "moment": "^2.24.0", | ||
| "lodash": "^4.17.15", | ||
@@ -30,0 +31,0 @@ "md5": "^2.2.1", |
+57
-50
@@ -5,11 +5,10 @@ const { expect } = require('chai') | ||
| const Request = require('../lib/request') | ||
| const moment = require('moment') | ||
| describe('JunTingSDK', () => { | ||
| const clientId = config.jtTConfig.GroupCode + '^' + config.jtTConfig.HotelCode + '^' + config.jtTConfig.account + '^' + config.jtTConfig.authorization | ||
| let sdk | ||
| const sdk = new JuntingSdk(config.jtTConfig) | ||
| let RoomType | ||
| let BusinessDate,Id,amount | ||
| before(async function () { | ||
| const data = await new Request().get(`http://112.17.72.71:8350/api/OAuth2/GetToken?clientId=${clientId}&clientSecret=${config.jtTConfig.password}`) | ||
| config.jtTConfig.access_token = data.Data.access_token | ||
| sdk = new JuntingSdk(config.jtTConfig) | ||
| await sdk.initReuqest() | ||
| }) | ||
@@ -20,12 +19,7 @@ | ||
| describe('getToken', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.getToken(clientId,config.jtTConfig.password) | ||
| expect(typeof res).to.eql('string') | ||
| }) | ||
| }) | ||
| //OK | ||
| describe('getHotelList', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.getHotelList(config.jtTConfig.GroupCode) | ||
| console.log('=======酒店========',res.Data.length,res.Data[0]) | ||
| expect(res.Code).to.eql(0) | ||
@@ -35,2 +29,3 @@ }) | ||
| //OK | ||
| describe('getHotelInfo', async () => { | ||
@@ -43,7 +38,8 @@ it('should be run success', async () => { | ||
| //todo | ||
| //OK | ||
| describe('getHotelRoomTypeList', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.getHotelRoomTypeList(config.jtTConfig.GroupCode, config.jtTConfig.HotelCode) | ||
| console.log('===res===========', res) | ||
| let res = await sdk.getHotelRoomTypeList(config.jtTConfig.GroupCode, config.jtTConfig.HotelCode, config.jtTConfig.ChannelCode) | ||
| RoomType = res.Data[3].RoomType | ||
| console.log('=======房型========',res.Data.length,res.Data[0]) | ||
| expect(res.Code).to.eql(0) | ||
@@ -53,7 +49,6 @@ }) | ||
| //todo | ||
| describe('getRoomTypeInfo', async () => { | ||
| //接口不存在 房型详情 | ||
| describe.skip('getRoomTypeInfo', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.getRoomTypeInfo(config.jtTConfig.GroupCode, config.jtTConfig.HotelCode, 'JZSC') | ||
| console.log('===res===========', res) | ||
| let res = await sdk.getRoomTypeInfo(config.jtTConfig.GroupCode, config.jtTConfig.HotelCode, RoomType, config.jtTConfig.ChannelCode) | ||
| expect(res.Code).to.eql(0) | ||
@@ -63,9 +58,11 @@ }) | ||
| //todo | ||
| //todo 房量 | ||
| describe('getHotelInventoryList', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.getHotelInventoryList( | ||
| 'crshks', 'JZDC', 'VIP1', | ||
| config.jtTConfig.ChannelCode, | ||
| RoomType, | ||
| '', | ||
| config.jtTConfig.GroupCode, config.jtTConfig.HotelCode) | ||
| console.log('==========res=========', res) | ||
| console.log('=======房量========',res.Data.length) | ||
| expect(res.Code).to.eql(0) | ||
@@ -75,9 +72,15 @@ }) | ||
| //todo | ||
| //Yes 房价 | ||
| describe('getHotelRoomRateList', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.getHotelRoomRateList( | ||
| 'crshks', 'JZDC', 'SH', | ||
| config.jtTConfig.GroupCode, config.jtTConfig.HotelCode) | ||
| console.log('==========res=========', res) | ||
| config.jtTConfig.ChannelCode, | ||
| RoomType, | ||
| 'VIP1', | ||
| config.jtTConfig.GroupCode, | ||
| config.jtTConfig.HotelCode) | ||
| console.log('=======房价========',res.Data.length,res.Data[0]) | ||
| BusinessDate = res.Data[0].BusinessDate | ||
| Id = res.Data[0].Id | ||
| amount = res.Data[0].ActualRate | ||
| expect(res.Code).to.eql(0) | ||
@@ -87,8 +90,11 @@ }) | ||
| //Yes | ||
| //Yes房价增量 | ||
| describe('getIncrementDailyRoomRateList', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.getIncrementDailyRoomRateList( | ||
| 'crshks', 'JZDC', 'SH', | ||
| config.jtTConfig.ChannelCode, | ||
| RoomType, | ||
| 'VIP1', | ||
| config.jtTConfig.GroupCode, config.jtTConfig.HotelCode) | ||
| console.log('=======房价增量========',res.Data.length) | ||
| expect(res.Code).to.eql(0) | ||
@@ -98,10 +104,10 @@ }) | ||
| //toDo | ||
| //YES | ||
| describe('createTrialOrder', async () => { | ||
| it('should be run success', async () => { | ||
| let res = await sdk.createTrialOrder( | ||
| 'crshks', | ||
| config.jtTConfig.ChannelCode, | ||
| '', | ||
| '', | ||
| 'JZDC', | ||
| RoomType, | ||
| 1, | ||
@@ -121,9 +127,10 @@ '', | ||
| it('should be run success', async () => { | ||
| console.log('======================================',RoomType,BusinessDate,amount) | ||
| let res = await sdk.createOrder( | ||
| 'feng1', | ||
| '13548585658', | ||
| 'test', | ||
| '15838755730', | ||
| 1, | ||
| 'JZDC', | ||
| 439, | ||
| 439, | ||
| RoomType, | ||
| amount, | ||
| amount, | ||
| '', | ||
@@ -133,11 +140,11 @@ '', | ||
| 0, | ||
| 'VIP1', | ||
| '', | ||
| '', | ||
| '', | ||
| 'BRK1', | ||
| '', | ||
| '', | ||
| 'CRSHKS', | ||
| '2018-03-13 11:51:35', | ||
| '2018-03-13 11:51:35', | ||
| config.jtTConfig.ChannelCode, | ||
| moment().startOf('day').add(0, 'days').format('YYYY-MM-DD'), | ||
| moment().startOf('day').add(1, 'days').format('YYYY-MM-DD'), | ||
| '18:00', | ||
@@ -150,12 +157,12 @@ 1, | ||
| 'J571005xionghy', | ||
| 439, | ||
| amount, | ||
| [ | ||
| { | ||
| 'ChannelCode': 'crshks', | ||
| 'BusinessDate': '2018-03-13', | ||
| 'RoomType': 'JZDC', | ||
| 'ChannelCode': config.jtTConfig.ChannelCode, | ||
| 'BusinessDate': '2020-03-19T00:00:00', | ||
| 'RoomType': 'BDKS', | ||
| 'RoomTypeAlias': null, | ||
| 'RateCode': 'VIP1', | ||
| 'RoomRate': 439, | ||
| 'ActualRate': 439, | ||
| 'RoomRate': 2888, | ||
| 'ActualRate': 2888, | ||
| 'IsContainBreakfast': false, | ||
@@ -167,3 +174,3 @@ 'PackeagesCode': 'NET', | ||
| 'Remarks': null, | ||
| 'Id': 4766, | ||
| 'Id': 68375, | ||
| 'GroupCode': '0003', | ||
@@ -173,4 +180,4 @@ 'HotelCode': 'J571005', | ||
| 'BusinessDateText': '03月13日', | ||
| 'RoomPrice': 439, | ||
| 'ActualRateText': '¥439' | ||
| 'RoomPrice': 11, | ||
| 'ActualRateText': '¥11' | ||
| } | ||
@@ -177,0 +184,0 @@ ], |
31539
3.28%871
2.96%5
25%+ Added
+ Added