diff --git a/src/pages/mobile/test/api.ts b/src/pages/mobile/test/api.ts index a5ebb03..9686188 100644 --- a/src/pages/mobile/test/api.ts +++ b/src/pages/mobile/test/api.ts @@ -4,7 +4,8 @@ import { generateSign } from "./utils/sign"; // API配置 const API_BASE_URL = "https://ckbapi.quwanzhi.com/v1/api"; -const API_KEY = "v3pzy-zcfkg-96jio-7xgh6-14kio"; +// 默认API Key(用于测试) +export const DEFAULT_API_KEY = "v3pzy-zcfkg-96jio-7xgh6-14kio"; export interface SubmitLeadParams { phone: string; @@ -24,17 +25,24 @@ export interface SubmitLeadResponse { /** * 提交线索到存客宝 + * @param params 线索参数 + * @param apiKey API密钥(必填) */ export async function submitLead( params: SubmitLeadParams, + apiKey: string, ): Promise { + if (!apiKey) { + throw new Error("apiKey不能为空"); + } + try { // 生成时间戳(秒级) const timestamp = Math.floor(Date.now() / 1000); // 构建请求参数 const requestParams: Record = { - apiKey: API_KEY, + apiKey: apiKey, timestamp, phone: params.phone, name: params.name, @@ -56,7 +64,7 @@ export async function submitLead( } // 生成签名 - const sign = generateSign(requestParams, API_KEY); + const sign = generateSign(requestParams, apiKey); requestParams.sign = sign; // 发送请求 diff --git a/src/pages/mobile/test/components/TestFormModal.tsx b/src/pages/mobile/test/components/TestFormModal.tsx index 95599ee..8c41209 100644 --- a/src/pages/mobile/test/components/TestFormModal.tsx +++ b/src/pages/mobile/test/components/TestFormModal.tsx @@ -1,8 +1,8 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Popup, Form, Input, TextArea, Button, Toast } from "antd-mobile"; import { CloseOutlined } from "@ant-design/icons"; import styles from "./TestFormModal.module.scss"; -import { submitLead } from "../api"; +import { submitLead, DEFAULT_API_KEY } from "../api"; interface TestFormModalProps { visible: boolean; @@ -11,6 +11,7 @@ interface TestFormModalProps { } export interface TestFormValues { + apiKey: string; phone: string; name: string; source: string; @@ -30,13 +31,19 @@ const TestFormModal: React.FC = ({ const values = await form.validateFields(); setLoading(true); + // 获取API Key,如果没有输入则使用默认值 + const apiKey = values.apiKey?.trim() || DEFAULT_API_KEY; + // 调用API提交数据 - const result = await submitLead({ - phone: values.phone, - name: values.name, - source: values.source, - remark: values.remark || undefined, - }); + const result = await submitLead( + { + phone: values.phone, + name: values.name, + source: values.source, + remark: values.remark || undefined, + }, + apiKey, + ); // 调用提交回调(如果提供) if (onSubmit) { @@ -64,9 +71,18 @@ const TestFormModal: React.FC = ({ const handleClose = () => { form.resetFields(); + // 重置时恢复默认API Key + form.setFieldsValue({ apiKey: DEFAULT_API_KEY }); onClose(); }; + // 初始化表单默认值 + useEffect(() => { + if (visible) { + form.setFieldsValue({ apiKey: DEFAULT_API_KEY }); + } + }, [visible, form]); + return ( = ({ } > + + + +