From 895a24b41eafddde82c94668d742613a333b6991 Mon Sep 17 00:00:00 2001 From: wangsijie Date: Fri, 27 May 2022 11:51:06 +0800 Subject: [PATCH] fix: alipay native --- packages/connector-alipay-native/src/index.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/connector-alipay-native/src/index.ts b/packages/connector-alipay-native/src/index.ts index 6e83850b6..5f1aa70d6 100644 --- a/packages/connector-alipay-native/src/index.ts +++ b/packages/connector-alipay-native/src/index.ts @@ -41,6 +41,20 @@ import { signingParameters } from './utils'; export type { AlipayNativeConfig } from './types'; +type CodePayload = { + auth_code: string; +}; + +const parseCodeFromJson = (json: string): string => { + try { + const { auth_code } = JSON.parse(json) as CodePayload; + + return auth_code; + } catch { + return json; + } +}; + export default class AlipayNativeConnector implements SocialConnector { public metadata: ConnectorMetadata = defaultMetadata; @@ -72,7 +86,7 @@ export default class AlipayNativeConnector implements SocialConnector { timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'), version: '1.0', grant_type: 'authorization_code', - code, + code: parseCodeFromJson(code), charset: 'UTF8', ...config, };