提交代码
This commit is contained in:
1 parent
30042caabb
commit
600f0c621c
108 files changed
+20109
-1605
No files matched your search
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
* 微信API接口
|
||||
* 提供微信JS-SDK所需的配置接口和相关功能
|
||||
*/
|
||||
|
||||
import { request } from '@/common/request.js';
|
||||
|
||||
/**
|
||||
* 微信配置信息接口
|
||||
*/
|
||||
export interface WeChatConfig {
|
||||
appId: string;
|
||||
timestamp: number;
|
||||
nonceStr: string;
|
||||
signature: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信配置请求参数
|
||||
*/
|
||||
export interface WeChatConfigParams {
|
||||
url: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信文件上传响应
|
||||
*/
|
||||
export interface WeChatUploadResponse {
|
||||
media_id: string;
|
||||
type: string;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信JS-SDK配置信息
|
||||
* @param url 当前页面URL
|
||||
* @returns Promise<WeChatConfig>
|
||||
*/
|
||||
export const getWeChatConfig = (url: string): Promise<WeChatConfig> => {
|
||||
return request({
|
||||
url: '/system/wechat/config',
|
||||
method: 'POST',
|
||||
data: { url }
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '获取微信配置失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 上传微信临时素材
|
||||
* @param mediaId 微信媒体文件ID
|
||||
* @param type 媒体类型 image/voice/video/thumb
|
||||
* @returns Promise<WeChatUploadResponse>
|
||||
*/
|
||||
export const uploadWeChatMedia = (mediaId: string, type: string): Promise<WeChatUploadResponse> => {
|
||||
return request({
|
||||
url: '/system/wechat/upload',
|
||||
method: 'POST',
|
||||
data: {
|
||||
media_id: mediaId,
|
||||
type: type
|
||||
}
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '上传微信媒体文件失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 下载微信临时素材
|
||||
* @param mediaId 微信媒体文件ID
|
||||
* @returns Promise<Blob>
|
||||
*/
|
||||
export const downloadWeChatMedia = (mediaId: string): Promise<Blob> => {
|
||||
return request({
|
||||
url: '/system/wechat/download',
|
||||
method: 'GET',
|
||||
data: { media_id: mediaId },
|
||||
responseType: 'blob'
|
||||
}).then(response => {
|
||||
if (response instanceof Blob) {
|
||||
return response;
|
||||
} else {
|
||||
throw new Error('下载微信媒体文件失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取微信用户信息
|
||||
* @param code 微信授权码
|
||||
* @returns Promise<any>
|
||||
*/
|
||||
export const getWeChatUserInfo = (code: string): Promise<any> => {
|
||||
return request({
|
||||
url: '/system/wechat/userinfo',
|
||||
method: 'GET',
|
||||
data: { code }
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '获取微信用户信息失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 生成微信支付订单
|
||||
* @param orderData 订单数据
|
||||
* @returns Promise<any>
|
||||
*/
|
||||
export const createWeChatPay = (orderData: any): Promise<any> => {
|
||||
return request({
|
||||
url: '/system/wechat/pay/create',
|
||||
method: 'POST',
|
||||
data: orderData
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '创建微信支付订单失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询微信支付订单状态
|
||||
* @param orderId 订单ID
|
||||
* @returns Promise<any>
|
||||
*/
|
||||
export const queryWeChatPayStatus = (orderId: string): Promise<any> => {
|
||||
return request({
|
||||
url: '/system/wechat/pay/query',
|
||||
method: 'GET',
|
||||
data: { order_id: orderId }
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '查询微信支付状态失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 微信分享统计
|
||||
* @param shareData 分享数据
|
||||
* @returns Promise<any>
|
||||
*/
|
||||
export const recordWeChatShare = (shareData: any): Promise<any> => {
|
||||
return request({
|
||||
url: '/system/wechat/share/record',
|
||||
method: 'POST',
|
||||
data: shareData
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '记录微信分享失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取微信分享配置
|
||||
* @param url 页面URL
|
||||
* @param type 分享类型 timeline/message
|
||||
* @returns Promise<any>
|
||||
*/
|
||||
export const getWeChatShareConfig = (url: string, type: string): Promise<any> => {
|
||||
return request({
|
||||
url: '/system/wechat/share/config',
|
||||
method: 'POST',
|
||||
data: { url, type }
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '获取微信分享配置失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 发送微信模板消息
|
||||
* @param templateData 模板消息数据
|
||||
* @returns Promise<any>
|
||||
*/
|
||||
export const sendWeChatTemplate = (templateData: any): Promise<any> => {
|
||||
return request({
|
||||
url: '/system/wechat/template/send',
|
||||
method: 'POST',
|
||||
data: templateData
|
||||
}).then(response => {
|
||||
if (response.code === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
throw new Error(response.msg || '发送微信模板消息失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 导出所有接口
|
||||
export default {
|
||||
getWeChatConfig,
|
||||
uploadWeChatMedia,
|
||||
downloadWeChatMedia,
|
||||
getWeChatUserInfo,
|
||||
createWeChatPay,
|
||||
queryWeChatPayStatus,
|
||||
recordWeChatShare,
|
||||
getWeChatShareConfig,
|
||||
sendWeChatTemplate
|
||||
};
|
||||
Reference in new issue
Block a user