一、问题背景
我的Go项目里面要对接阿里的支付功能,需要导入相关的包
github.com/smartwalle/alipay/v3

二、问题现象
按照https://github.com/smartwalle/alipay/tree/master的提示,使用命令
go get github.com/smartwalle/alipay/v3
一直报错提示“go: module github.com/smartwalle/alipay@upgrade found (v1.0.2), but does not contain package github.com/smartwalle/alipay/v3”

三、寻找原因
1.开始以为是我的go版本太低,本地安装的Go1.17, 于是升级到了Go1.20, 但是依然无法导入github.com/smartwalle/alipay/v3
2.在我使用go mod tidy 时发现包来自于:https://mirrors.aliyun.com/goproxy/
, 日志如下:
PS C:\goproject1> go mod tidy
goproject1/controller imports
github.com/gin-gonic/gin imports
github.com/gin-gonic/gin/binding imports
google.golang.org/protobuf/proto imports
google.golang.org/protobuf/reflect/protoregistry tested by
google.golang.org/protobuf/reflect/protoregistry.test imports
github.com/google/go-cmp/cmp/cmpopts imports
golang.org/x/xerrors loaded from golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543,
but go 1.16 would select v0.0.0-20200804184101-5ec99f83aff1
goproject1/controller imports
github.com/gin-gonic/gin imports
github.com/gin-gonic/gin/binding imports
https://mirrors.aliyun.com/goproxy/

一直记得自己配置过go env -w GOPROXY=https://goproxy.cn,而且不曾手动修改这个配置

四、解决办法
重新配置go env 的proxy,操作如下:
PS C:\goproject1> go env -w GOPROXY=https://goproxy.cn
PS C:\goproject1> go env GOPROXY
https://goproxy.cn
PS C:\goproject1> go env GOPROXY
https://goproxy.cn
然后加载github.com/smartwalle/alipay/v3
PS C:\goproject1> go get github.com/smartwalle/alipay/v3
go: downloading github.com/smartwalle/alipay/v3 v3.1.8
go: downloading github.com/smartwalle/crypto4go v1.0.2
go: added github.com/smartwalle/alipay/v3 v3.1.8
go: added github.com/smartwalle/crypto4go v1.0.2
PS C:\goproject1>

操作成功

五、分析原因
https://mirrors.aliyun.com/goproxy/的库中应该是没有alipay的v3版本,而https://goproxy.cn中有此版本。
事后搜索了相关原因,在下面这篇文章中也有类似问题,解决方法相同:
https://blog.csdn.net/shupili141005/article/details/127803546

遗憾的是暂且未找到go env从https://goproxy.cn变更到https://mirrors.aliyun.com/goproxy/的原因,想不起来自己什么时候修改了这个配置