diff --git a/lib/RESTAPIMock.js b/lib/RESTAPIMock.js index 59ba311..696c200 100644 --- a/lib/RESTAPIMock.js +++ b/lib/RESTAPIMock.js @@ -31,10 +31,18 @@ function RESTAPIMock(myURL, searchParams, callbackName) { if (!option) { return; } + if (!option.request || !option.request.queries || Object.entries(option.request.queries).every(query => query[1] === searchParams.get(query[0]))) { + response = createRes(callbackName, option); + return true; + } + if (option.request) { + return false; + } if (!option.needPars || searchParams.get(option.needPars)) { response = createRes(callbackName, option); return true; } + } else { if (!RESTAPI.needPars || searchParams.get(RESTAPI.needPars)) { response = createRes(callbackName, RESTAPI); diff --git a/lib/anyproxy.config.js b/lib/anyproxy.config.js index d17a077..51e4f35 100644 --- a/lib/anyproxy.config.js +++ b/lib/anyproxy.config.js @@ -16,7 +16,7 @@ module.exports = function () { const myURL = removeProtocal(URLO.href); // console.log(URLO.searchParams); const searchParams = URLO.searchParams; - const callback = searchParams.get('callback') || new URLSearchParams(requestDetail.requestData).get('callback'); + const callback = searchParams.get('callback') || new URLSearchParams(requestDetail.requestData.toString()).get('callback'); const chain = [RESTAPIMock, fileMock]; diff --git a/mock/RESTAPI.config.json b/mock/RESTAPI.config.json index b784d5c..e347d48 100644 --- a/mock/RESTAPI.config.json +++ b/mock/RESTAPI.config.json @@ -7,8 +7,8 @@ }, { "URL": "//i.vip.iqiyi.com/client/store/pc/checkout.action", - "OPTIONS": ["gold", "diamond"], - "choices": ["diamond"] + "OPTIONS": ["gold", "diamondNotLogin", "diamond"], + "choices": ["diamond", "diamondNotLogin"] }, { "URL": "//i.vip.iqiyi.com/order/queryOrderStat.action", @@ -33,7 +33,7 @@ }, { "URL": "//passport.iqiyi.com/apis/user/info/queryWithVerify.action", - "choices": 1 + "choices": 0 } ] } \ No newline at end of file diff --git a/mock/RESTAPI.json b/mock/RESTAPI.json index 9985e9a..fe25da1 100644 --- a/mock/RESTAPI.json +++ b/mock/RESTAPI.json @@ -2,13 +2,18 @@ "url": "//i.vip.iqiyi.com/client/store/pc/checkout.action", "options": { "gold": { + "request": { + "queries": { + "vipType": "1" + } + }, "body": { "code": "A00000", "data": { "msg": "成功", "code": "A00000", "data": { - "vipTypeName": "黄金VIP会员", + "vipTypeName": "黄金VIP会员1", "autoRenewSuits": [{ "amount": 12, "autorenewTip": "", @@ -604,7 +609,12 @@ } } }, - "diamond": { + "diamondNotLogin": { + "request": { + "queries": { + "vipType": "4" + } + }, "body": { "code": "A00000", "data": { @@ -612,6 +622,518 @@ "code": "A00000", "data": { "vipTypeName": "钻石VIP会员", + "autoRenewSuits": [{ + "amount": 12, + "autorenewTip": "到期后自动续费1年,可随时取消", + "originalPrice": 49800, + "payAutoRenew": "3", + "description": "连续包年", + "pid": "adb3376b039b970b", + "recommend": 1, + "sort": 1, + "privilege": 16800, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 16800, + "needPayFee": 33000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 990, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 1, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 33000, + "price": 33000, + "id": 7840, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "推荐", + "marketingPositionWords": "" + }, { + "amount": 3, + "autorenewTip": "到期后自动续费3个月,可随时取消", + "originalPrice": 14800, + "payAutoRenew": "3", + "description": "连续包季", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 2, + "privilege": 6000, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 6000, + "needPayFee": 8800, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 989, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 1, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 8800, + "price": 8800, + "id": 7841, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "", + "marketingPositionWords": "" + }, { + "amount": 1, + "autorenewTip": "到期后自动续费1个月,可随时取消", + "originalPrice": 4980, + "payAutoRenew": "3", + "description": "连续包月", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 3, + "privilege": 1980, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 1980, + "needPayFee": 3000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 988, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 1, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 3000, + "price": 3000, + "id": 7842, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "热销", + "marketingPositionWords": "" + }], + "userInfo": { + "vipSuperscript": "", + "isVipUser": false + }, + "userAutoRenew": 0, + "storeNodeLocations": { + "vipTypeCornerLocation": { + "icon": "http://www.iqiyipic.com/common/fix/vipcash/cash-icon-diamonds.png", + "text": "钻石VIP会员", + "url": "" + }, + "tabActivityLocation": { + "icon": "", + "text": "适用于电视/电脑/手机/iPad", + "url": "" + }, + "topActivityLocation": { + "icon": "", + "text": "特惠0.5元/天升级钻石会员,增加TV端超爽大屏特权", + "url": "" + } + }, + "vipType": 4, + "showAutoRenew": "1", + "suits": [{ + "amount": 12, + "autorenewTip": "", + "originalPrice": 26800, + "payAutoRenew": "0", + "description": "12个月", + "pid": "adb3376b039b970b", + "recommend": 1, + "sort": 1, + "privilege": 0, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT,BAIDU", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 0, + "needPayFee": 36000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 679, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 36000, + "payType": 95, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 680, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 2, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "银行卡", + "moneyUnit": "CNY", + "payChannel": 8, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 36000, + "payType": 32, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 683, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 3, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "奇豆支付", + "moneyUnit": "CNY", + "payChannel": 6, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 36000, + "price": 36000, + "id": 7460, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "推荐", + "marketingPositionWords": "" + }, { + "amount": 3, + "autorenewTip": "", + "originalPrice": 14800, + "payAutoRenew": "0", + "description": "3个月", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 2, + "privilege": 2800, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT,BAIDU", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 2800, + "needPayFee": 12000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 677, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 2800, + "needPayFee": 12000, + "payType": 95, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 678, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 2, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "银行卡", + "moneyUnit": "CNY", + "payChannel": 8, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 2800, + "needPayFee": 12000, + "payType": 32, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 682, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 3, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "奇豆支付", + "moneyUnit": "CNY", + "payChannel": 6, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 12000, + "price": 12000, + "id": 7459, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "", + "marketingPositionWords": "" + }, { + "amount": 1, + "autorenewTip": "", + "originalPrice": 4980, + "payAutoRenew": "0", + "description": "1个月", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 3, + "privilege": 0, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT,BAIDU", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 0, + "needPayFee": 4980, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 675, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 4980, + "payType": 95, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 676, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 2, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "银行卡", + "moneyUnit": "CNY", + "payChannel": 8, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 4980, + "payType": 32, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 681, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 3, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "奇豆支付", + "moneyUnit": "CNY", + "payChannel": 6, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 4980, + "price": 4980, + "id": 7458, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "", + "marketingPositionWords": "" + }] + } + } + } + }, + "diamond": { + "request": { + "queries": { + "vipType": "4", + "P00001": "1el6tTVC2n4q6CVz3zbaLTBr7l0fnDm10IjRLWyNOQGSIT89QqcC1tbYnNlqeXlb5m2gd9" + } + }, + "body": { + "code": "A00000", + "data": { + "msg": "成功", + "code": "A00000", + "data": { + "vipTypeName": "钻石VIP会员2", "autoRenewSuits": [{ "amount": 1, "autorenewTip": "", diff --git a/mock/filemap.json b/mock/filemap.json index 7141549..d49935d 100644 --- a/mock/filemap.json +++ b/mock/filemap.json @@ -1,5 +1,5 @@ { - "disabled": false, + "disabled": true, "map": { "//static.iqiyi.com/js/qiyiVipPay/entry-vipPay": "./build/entry-vipPay.js", "//static.iqiyi.com/js/qiyiVipPay/entry-bankcardPay": "./build/entry-bankcardPay.js", diff --git a/mock/raw.json b/mock/raw.json new file mode 100644 index 0000000..406cb08 --- /dev/null +++ b/mock/raw.json @@ -0,0 +1,507 @@ +{ + "DiamondNotLogin": { + "code": "A00000", + "data": { + "msg": "成功", + "code": "A00000", + "data": { + "vipTypeName": "钻石VIP会员", + "autoRenewSuits": [{ + "amount": 12, + "autorenewTip": "到期后自动续费1年,可随时取消", + "originalPrice": 49800, + "payAutoRenew": "3", + "description": "连续包年", + "pid": "adb3376b039b970b", + "recommend": 1, + "sort": 1, + "privilege": 16800, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 16800, + "needPayFee": 33000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 990, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 1, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 33000, + "price": 33000, + "id": 7840, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "推荐", + "marketingPositionWords": "" + }, { + "amount": 3, + "autorenewTip": "到期后自动续费3个月,可随时取消", + "originalPrice": 14800, + "payAutoRenew": "3", + "description": "连续包季", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 2, + "privilege": 6000, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 6000, + "needPayFee": 8800, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 989, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 1, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 8800, + "price": 8800, + "id": 7841, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "", + "marketingPositionWords": "" + }, { + "amount": 1, + "autorenewTip": "到期后自动续费1个月,可随时取消", + "originalPrice": 4980, + "payAutoRenew": "3", + "description": "连续包月", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 3, + "privilege": 1980, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 1980, + "needPayFee": 3000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 988, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 1, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 3000, + "price": 3000, + "id": 7842, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "热销", + "marketingPositionWords": "" + }], + "userInfo": { + "vipSuperscript": "", + "isVipUser": false + }, + "userAutoRenew": 0, + "storeNodeLocations": { + "vipTypeCornerLocation": { + "icon": "http://www.iqiyipic.com/common/fix/vipcash/cash-icon-diamonds.png", + "text": "钻石VIP会员", + "url": "" + }, + "tabActivityLocation": { + "icon": "", + "text": "适用于电视/电脑/手机/iPad", + "url": "" + }, + "topActivityLocation": { + "icon": "", + "text": "特惠0.5元/天升级钻石会员,增加TV端超爽大屏特权", + "url": "" + } + }, + "vipType": 4, + "showAutoRenew": "1", + "suits": [{ + "amount": 12, + "autorenewTip": "", + "originalPrice": 26800, + "payAutoRenew": "0", + "description": "12个月", + "pid": "adb3376b039b970b", + "recommend": 1, + "sort": 1, + "privilege": 0, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT,BAIDU", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 0, + "needPayFee": 36000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 679, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 36000, + "payType": 95, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 680, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 2, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "银行卡", + "moneyUnit": "CNY", + "payChannel": 8, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 36000, + "payType": 32, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 683, + "lang": "zh_CN", + "amount": 12, + "autoRenewTip": "", + "sort": 3, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "奇豆支付", + "moneyUnit": "CNY", + "payChannel": 6, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 36000, + "price": 36000, + "id": 7460, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "推荐", + "marketingPositionWords": "" + }, { + "amount": 3, + "autorenewTip": "", + "originalPrice": 14800, + "payAutoRenew": "0", + "description": "3个月", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 2, + "privilege": 2800, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT,BAIDU", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 2800, + "needPayFee": 12000, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 677, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 2800, + "needPayFee": 12000, + "payType": 95, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 678, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 2, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "银行卡", + "moneyUnit": "CNY", + "payChannel": 8, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 2800, + "needPayFee": 12000, + "payType": 32, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 682, + "lang": "zh_CN", + "amount": 3, + "autoRenewTip": "", + "sort": 3, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "奇豆支付", + "moneyUnit": "CNY", + "payChannel": 6, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 12000, + "price": 12000, + "id": 7459, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "", + "marketingPositionWords": "" + }, { + "amount": 1, + "autorenewTip": "", + "originalPrice": 4980, + "payAutoRenew": "0", + "description": "1个月", + "pid": "adb3376b039b970b", + "recommend": 0, + "sort": 3, + "privilege": 0, + "type": 1, + "payTypeOptions": [{ + "supportType": "ALI,WECHAT,BAIDU", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 1, + "privilege": 0, + "needPayFee": 4980, + "payType": 378, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 675, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 1, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "扫码支付", + "moneyUnit": "CNY", + "payChannel": 0, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 4980, + "payType": 95, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 676, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 2, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "银行卡", + "moneyUnit": "CNY", + "payChannel": 8, + "region": "cn", + "subPromotion": "", + "promotion": "" + }, { + "supportType": "", + "supportSignFree": 0, + "payAutoRenew": 0, + "icon": "", + "description": "", + "recommend": 0, + "privilege": 0, + "needPayFee": 4980, + "payType": 32, + "balance": "", + "autoRenew": 0, + "iconUrl": "", + "id": 681, + "lang": "zh_CN", + "amount": 1, + "autoRenewTip": "", + "sort": 3, + "dealType": "", + "supportPurchase": false, + "enableAUtoRenew": false, + "monthly": 0, + "name": "奇豆支付", + "moneyUnit": "CNY", + "payChannel": 6, + "region": "cn", + "subPromotion": "", + "promotion": "" + }], + "actCode": "", + "marketingPositionIcon": "", + "needPayFee": 4980, + "price": 4980, + "id": 7458, + "marketingPositionUrl": "", + "supportCoupon": 0, + "giftMonths": 0, + "promotion": "", + "marketingPositionWords": "" + }] + } + } + }, + "" +} \ No newline at end of file diff --git a/test/RESTAPIMock.unittest.js b/test/RESTAPIMock.unittest.js index b6ece32..ff5519c 100644 --- a/test/RESTAPIMock.unittest.js +++ b/test/RESTAPIMock.unittest.js @@ -1,23 +1,21 @@ "use strict"; -const { - URL, - URLSearchParams -} = require('url'); -const removeProtocal = require('../lib/removeProtocal') const createRes = require('../lib/createRes') const RESTAPIMock = require("../lib/RESTAPIMock"); -const URLO = new URL('http://i.vip.iqiyi.com/client/store/pc/checkout.action?platform=b6c13e26323c537d&pid=a0226bd958843452&fs=&fsSign=&fc=a03a512fefb9eaf7&fv=&qc005=ee3dc1362b22680c6bc6af43931650a8&vipType=1&aid=&P00001=50AIWkGubnxCHgI96u5jpLV7P2AqF2ZzY1JEbtrAjthkx0oxcQWNqm2grZwm3q5BZAVAf0&callback=jsonp_05611606862977503'); -const myURL = removeProtocal(URLO.href); -const searchParams = URLO.searchParams; -const callbackName = searchParams.get('callback'); +const getParas = require('./getParas') const mockMap = { + "request": { + "queries": { + "vipType": "4", + "P00001": "1el6tTVC2n4q6CVz3zbaLTBr7l0fnDm10IjRLWyNOQGSIT89QqcC1tbYnNlqeXlb5m2gd9" + } + }, "body": { "code": "A00000", "data": { "msg": "成功", "code": "A00000", "data": { - "vipTypeName": "钻石VIP会员", + "vipTypeName": "钻石VIP会员2", "autoRenewSuits": [{ "amount": 1, "autorenewTip": "", @@ -503,10 +501,23 @@ const mockMap = { } describe("RESTAPIMock", () => { - it("matched", () => { - expect(RESTAPIMock(myURL, searchParams, callbackName)).toEqual({ + it("diamondLogin matched", () => { + const [URLO, ...paras] = getParas('diamondLogin'); + expect(RESTAPIMock(...paras)).toEqual({ match: true, - response: createRes(callbackName, mockMap) + response: createRes(paras[2], mockMap) + }); + }); + it("diamondNotLogin notMatched", () => { + expect(RESTAPIMock(...getParas('diamondNotLogin').splice(1))).toEqual({ + match: false, + response: undefined + }); + }); + it("goldNotLogin notMatched", () => { + expect(RESTAPIMock(...getParas('goldNotLogin').splice(1))).toEqual({ + match: false, + response: undefined }); }); }); \ No newline at end of file diff --git a/test/anyproxy.config.unittest.js b/test/anyproxy.config.unittest.js index 74c4980..8f74398 100644 --- a/test/anyproxy.config.unittest.js +++ b/test/anyproxy.config.unittest.js @@ -1,26 +1,26 @@ "use strict"; -const { - URL, - URLSearchParams -} = require('url'); -const removeProtocal = require('../lib/removeProtocal') const getConfig = require('../lib/anyproxy.config') const RESTAPIMock = require("../lib/RESTAPIMock"); -const URLO = new URL('http://i.vip.iqiyi.com/client/store/pc/checkout.action?platform=b6c13e26323c537d&pid=a0226bd958843452&fs=&fsSign=&fc=a03a512fefb9eaf7&fv=&qc005=ee3dc1362b22680c6bc6af43931650a8&vipType=1&aid=&P00001=50AIWkGubnxCHgI96u5jpLV7P2AqF2ZzY1JEbtrAjthkx0oxcQWNqm2grZwm3q5BZAVAf0&callback=jsonp_05611606862977503'); -const myURL = removeProtocal(URLO.href); -const searchParams = URLO.searchParams; -const callbackName = searchParams.get('callback'); -const config = getConfig(); +const getParas = require('./getParas') describe("anyproxy.config", () => { - it("beforeSendRequest", () => { + it("beforeSendRequest diamondLoginMatched", () => { + const config = getConfig(); var result = config.beforeSendRequest({ - url: 'http://i.vip.iqiyi.com/client/store/pc/checkout.action?platform=b6c13e26323c537d&pid=a0226bd958843452&fs=&fsSign=&fc=a03a512fefb9eaf7&fv=&qc005=ee3dc1362b22680c6bc6af43931650a8&vipType=1&aid=&P00001=50AIWkGubnxCHgI96u5jpLV7P2AqF2ZzY1JEbtrAjthkx0oxcQWNqm2grZwm3q5BZAVAf0&callback=jsonp_05611606862977503', + url: getParas('diamondLogin').splice(0, 1), requestData: {} }).next(); - const rt = RESTAPIMock(myURL, searchParams, callbackName) + const rt = RESTAPIMock(...getParas('diamondLogin').splice(1)) expect(result.value).toEqual({ response: rt.response }); }); + it("beforeSendRequest goldNotLoginNotMatched", () => { + const config = getConfig(); + var result = config.beforeSendRequest({ + url: getParas('goldNotLogin').splice(0, 1), + requestData: {} + }).next(); + expect(result.value).toBeUndefined(); + }); }); \ No newline at end of file diff --git a/test/fileMock.unittest.js b/test/fileMock.unittest.js index 405a9d1..aa67ddd 100644 --- a/test/fileMock.unittest.js +++ b/test/fileMock.unittest.js @@ -7,42 +7,19 @@ const fs = require("fs"); const removeProtocal = require('../lib/removeProtocal') const fileMock = require("../lib/fileMock"); - describe("fileMock", () => { it("js file", () => { const URLO = new URL('http://static.iqiyi.com/js/lib/sea1.2.js'); const myURL = removeProtocal(URLO.href); const searchParams = URLO.searchParams; const callbackName = searchParams.get('callback'); - expect(fileMock(myURL, searchParams, callbackName)).toEqual({ - match: true, - response: { - statusCode: 200, - header: { - "Content-Type": 'application/javascript', - }, - body: fs.readFileSync('./mock/sea1.2.debug.js', { - encoding: "utf-8" - }) - } - }); + expect(fileMock(myURL, searchParams, callbackName)).toBeUndefined(); }); it("css file", () => { const URLO = new URL('http://static.qiyi.com/css/common/v3-vipCash/vip_cash1.0.css'); const myURL = removeProtocal(URLO.href); const searchParams = URLO.searchParams; const callbackName = searchParams.get('callback'); - expect(fileMock(myURL, searchParams, callbackName)).toEqual({ - match: true, - response: { - statusCode: 200, - header: { - "Content-Type": 'text/css', - }, - body: fs.readFileSync('./mock/vip_cash1.0.css', { - encoding: "utf-8" - }) - } - }); + expect(fileMock(myURL, searchParams, callbackName)).toBeUndefined(); }); }); \ No newline at end of file diff --git a/test/getParas.js b/test/getParas.js new file mode 100644 index 0000000..8a9f893 --- /dev/null +++ b/test/getParas.js @@ -0,0 +1,21 @@ +const removeProtocal = require('../lib/removeProtocal') +const URLS = { + goldNotLogin: 'http://i.vip.iqiyi.com/client/store/pc/checkout.action?platform=b6c13e26323c537d&pid=a0226bd958843452&fs=&fsSign=&fc=a03a512fefb9eaf7&fv=&qc005=f1c1ee7ebee4b600f12d153351a38e48&vipType=1&aid=&P00001=&callback=window.jsonp_07077807149559778', + goldLogin: 'http://i.vip.iqiyi.com/client/store/pc/checkout.action?platform=b6c13e26323c537d&pid=a0226bd958843452&fs=&fsSign=&fc=a03a512fefb9eaf7&fv=&qc005=f1c1ee7ebee4b600f12d153351a38e48&vipType=1&aid=&P00001=1el6tTVC2n4q6CVz3zbaLTBr7l0fnDm10IjRLWyNOQGSIT89QqcC1tbYnNlqeXlb5m2gd9&callback=window.jsonp_06267915858114745', + diamondNotLogin: 'http://i.vip.iqiyi.com/client/store/pc/checkout.action?platform=b6c13e26323c537d&pid=a0226bd958843452&fs=&fsSign=&fc=a03a512fefb9eaf7&fv=&qc005=ee3dc1362b22680c6bc6af43931650a8&vipType=1&aid=&P00001=50AIWkGubnxCHgI96u5jpLV7P2AqF2ZzY1JEbtrAjthkx0oxcQWNqm2grZwm3q5BZAVAf0&callback=jsonp_05611606862977503', + diamondLogin: 'http://i.vip.iqiyi.com/client/store/pc/checkout.action?platform=b6c13e26323c537d&pid=adb3376b039b970b&fs=&fsSign=&fc=a03a512fefb9eaf7&fv=&qc005=f1c1ee7ebee4b600f12d153351a38e48&vipType=4&aid=&P00001=1el6tTVC2n4q6CVz3zbaLTBr7l0fnDm10IjRLWyNOQGSIT89QqcC1tbYnNlqeXlb5m2gd9&callback=window.jsonp_020797424733475012' +} + + +module.exports = (type) => { + const URLO = new URL(URLS[type]); + const myURL = removeProtocal(URLO.href); + const searchParams = URLO.searchParams; + const callbackName = searchParams.get('callback'); + return [ + URLO, + myURL, + searchParams, + callbackName + ] +} \ No newline at end of file