收藏
回答

自建APIserver访问异常,如何解决?

// 部署模式:用阿里云的 ECS 放开的公网地址 https测试不成功

//apiUrl: 'http://47.93.203.133:8004',

apiUrl: 'https://api.petroemall.cn',

// 开发模式:使用本地地址(需要在微信开发者工具中勾选"不校验合法域名")

//apiUrl: 'http://localhost:8004',

https://api.petroemall.cn与http://47.93.203.133:8004,是一台服务器,前面的是通过服务器安装caddy对外提供HTTPS的,以满足微信对域名的要求。

问题是http的完全正常,本地开发模式下也完全正常,一旦切换到正式部署,就不行,接口报错

index.js? [sm]:56 ❌ 加载用户列表失败详情: {errMsg: "request:fail", errno: undefined, statusCode: undefined, url: "https://api.petroemall.cn/api/users"}

排错过程:

1.本地curl 及nscurl测试如下:

mac@Kai-MBP fidata-wx % curl -v https://api.petroemall.cn/api/users

* Host api.petroemall.cn:443 was resolved.

* IPv6: (none)

* IPv4: 47.93.203.133

*   Trying 47.93.203.133:443...

* Connected to api.petroemall.cn (47.93.203.133) port 443

* ALPN: curl offers h2,http/1.1

* (304) (OUT), TLS handshake, Client hello (1):

*  CAfile: /etc/ssl/cert.pem

*  CApath: none

* Recv failure: Connection reset by peer

* LibreSSL/3.3.6: error:02FFF036:system library:func(4095):Connection reset by peer

* Closing connection

curl: (35) Recv failure: Connection reset by peer

这是在开发者端进行curl测试的情况,出错。

奇怪的是用nscul正常?

mac@Kai-MBP fidata-wx % nscurl -v https://api.petroemall.cn/api/users

2026-04-09 09:09:41.056 nscurl[5234:68887] session <__NSURLSessionLocal: 0x7f8ef0a06a60> task LocalDataTask <C0492649-D02F-42FE-A315-C29AD655A811>.<1> will not use effective configuration

{"code":200,"data":{"users":[{"id":1,"fidata_id":"fi-8LOIJPKC","name":"凯叔","email":"chenyongkai0@qq.com","broker_name":null,"broker_account":null,"fund_account":null,"bank_name":null,"bank_account":null}]}}%                   

2.直接用浏览器访问接口,浏览器直接输入 https://api.petroemall.cn/api/users,返回结果正常。

4.编写简单python程序访问端口,也正常返回。

6.初步结论,经过检查,应该是小程序运行环境对https服务器访问问题,经排查通讯链路,包括排除防火墙,阿里云通讯问题,均正常,定位为小程序运行环境与远端API服务器的通讯问题。

能否帮忙解决?

回答关注问题邀请回答
收藏

2 个回答

  • Mr.Zhao
    Mr.Zhao
    04-09

    这就是你说的浏览器访问正常啊

    04-09
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    04-09
    有用
    回复
登录 后发表内容