sign check fail: check Sign and Data Fail解决方案

这篇博客介绍了在遇到支付宝接口返回'check Sign and Data Fail'错误时的问题分析和解决方案。错误主要是由于使用了错误的支付宝公钥,开发者需要注意区分应用公钥和支付宝公钥。正确做法是根据不同的环境(沙箱、线上openapi网关、mapi网关)使用相应的支付宝公钥,并提供了公钥查看地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我们先看一下类似的错误信息如下:

com.alipay.api.AlipayApiException: sign check fail: check Sign and Data Fail


这里着重说明,报这个错误是因为支付宝公钥(alipay_public_key)使用错误导致的!

很多开发者把自己生成的应用公钥和支付宝公钥容易搞混淆!

从而配置错误导致这个错误,自己生成的是应用公钥和应用私钥!


import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'; export type ContentType = | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream'; export interface RequestOption<ResponseData = any> { /** * The hook before request * * For example: You can add header token in this hook * * @param config Axios config */ onRequest: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>; /** * The hook to check backend response is success or not * * @param response Axios response */ isBackendSuccess: (response: AxiosResponse<ResponseData>) => boolean; /** * The hook after backend request fail * * For example: You can handle the expired token in this hook * * @param response Axios response * @param instance Axios instance */ onBackendFail: ( response: AxiosResponse<ResponseData>, instance: AxiosInstance ) => Promise<AxiosResponse | null> | Promise<void>; /** * transform backend response when the responseType is json * * @param response Axios response */ transformBackendResponse(response: AxiosResponse<ResponseData>): any | Promise<any>; /** * The hook to handle error * * For example: You can show error message in this hook * * @param error */ onError: (error: AxiosError<ResponseData>) => void | Promise<void>; } interface ResponseMap { blob: Blob; text: string; arrayBuffer: ArrayBuffer; stream: ReadableStream<Uint8Array>; document: Document; } export type ResponseType = keyof ResponseMap | 'json'; export type MappedType<R extends ResponseType, JsonType = any> = R extends keyof ResponseMap ? ResponseMap[R] : JsonType; export type CustomAxiosRequestConfig<R extends ResponseType = 'json'> = Omit<AxiosRequestConfig, 'responseType'> & { responseType?: R; }; export interface RequestInstanceCommon<T> { /** * cancel the request by request id * * if the request provide abort controller sign from config, it will not collect in the abort controller map * * @param requestId */ cancelRequest: (requestId: string) => void; /** * cancel all request * * if the request provide abort controller sign from config, it will not collect in the abort controller map */ cancelAllRequest: () => void; /** you can set custom state in the request instance */ state: T; } /** The request instance */ export interface RequestInstance<S = Record<string, unknown>> extends RequestInstanceCommon<S> { <T = any, R extends ResponseType = 'json'>(config: CustomAxiosRequestConfig<R>): Promise<MappedType<R, T>>; } export type FlatResponseSuccessData<T = any, ResponseData = any> = { data: T; error: null; response: AxiosResponse<ResponseData>; }; export type FlatResponseFailData<ResponseData = any> = { data: null; error: AxiosError<ResponseData>; response: AxiosResponse<ResponseData>; }; export type FlatResponseData<T = any, ResponseData = any> = | FlatResponseSuccessData<T, ResponseData> | FlatResponseFailData<ResponseData>; export interface FlatRequestInstance<S = Record<string, unknown>, ResponseData = any> extends RequestInstanceCommon<S> { <T = any, R extends ResponseType = 'json'>( config: CustomAxiosRequestConfig<R> ): Promise<FlatResponseData<MappedType<R, T>, ResponseData>>; } 这是type.ts
最新发布
07-24
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值