当前位置:   article > 正文

Axios 配置使用SSL证书 (微信退款)_axios ssl

axios ssl

axios 封装 

  1. import axios, { AxiosInstance, AxiosResponse } from 'axios';
  2. /**
  3. * 基于Axios框架实现的Http工具
  4. */
  5. export class HttpUtils {
  6. private readonly axios: AxiosInstance;
  7. constructor(_timeout: number = 5000) {
  8. this.axios = axios.create({
  9. timeout: _timeout
  10. });
  11. }
  12. async postSSL(url: string, data: any = {}, headers: object = {}, contentType: string, httpsAgent): Promise<AxiosResponse> {
  13. const config = {}
  14. config['headers'] = headers;
  15. config['headers']['content-type'] = contentType;
  16. config['httpsAgent'] = httpsAgent;
  17. const response: AxiosResponse = await this.axios.post(url, data, config);
  18. return response
  19. }
  20. }
  21. export default new HttpUtils()

测试 

  1. import * as https from 'https'
  2. import * as fs from 'fs'
  3. import HttpUtils from './HttpUtils'
  4. const certPath = '/ext/aaa/bb/apiclient_cert.p12'
  5. const cretPwd = '证书密码'
  6. cosnt WX_REFUND_APPLY_API = '微信退款API地址'
  7. const refundXML = '退款请求XML'
  8. //测试
  9. (
  10. async()=>{
  11. const pfx = fs.readFileSync('certPath');
  12. const agent = new https.Agent({
  13. pfx,
  14. passphrase: apiCretPwd
  15. });
  16. const response = await HttpUtils.postSSL(WX_REFUND_APPLY_API, refundXML, {}, 'text/html', agent)
  17. }
  18. )()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/283481
推荐阅读
相关标签
  

闽ICP备14008679号