-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
138 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Koa from 'koa' | ||
import { api2DProfile } from '../service/vendor.mjs' | ||
|
||
export default class VendorController { | ||
/** | ||
* 获取vendor用户信息 | ||
* @param ctx | ||
*/ | ||
public static async postApi2DProfile(ctx: Koa.Context) { | ||
await api2DProfile(ctx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { router } from './index.mjs' | ||
import VendorController from '../controller/vendor.mjs' | ||
|
||
router.post('/userProfile/api2d', VendorController.postApi2DProfile) | ||
|
||
export { router } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Context } from 'koa' | ||
import fetch from 'node-fetch' | ||
import proxy from 'https-proxy-agent' | ||
import debugLibrary from 'debug' | ||
|
||
const debug = debugLibrary('vendor') | ||
|
||
export async function api2DProfile(ctx: Context) { | ||
try { | ||
const res = await fetch(`https://api.api2d.com/user/profile`, { | ||
method: 'POST', | ||
headers: { | ||
authorization: 'Bearer 100037|WOdHl3svgUPJdKIMkqlbSZbl7YjOXxHqTEVVtyFa', | ||
Accept: 'application/json' | ||
}, | ||
agent: proxy(process.env.CUSTOM_PROXY) | ||
}) | ||
const data: any = await res.json() | ||
debug('api2DProfile result: ', data) | ||
if (data.code === 0) { | ||
ctx.body = { | ||
code: 200, | ||
msg: 'ok', | ||
data: data.data.profile, | ||
success: true | ||
} | ||
} else { | ||
ctx.body = { | ||
code: 500, | ||
msg: data.msg || 'error', | ||
data: data, | ||
success: false | ||
} | ||
} | ||
} catch (e) { | ||
debug('api2DProfile error: ', e) | ||
ctx.body = { | ||
code: 500, | ||
msg: e.message || 'error', | ||
data: null, | ||
success: false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters