案例分享:基于golang的支付宝支付


本文摘自php中文网,作者藏色散人,侵删。

基于 golang 的支付宝支付小案例

  • golang 【单例模式】实现支付宝网页扫码支付和手机端支付

使用步骤

1

2

3

4

5

git clone git@github.com:yangliang4488/ali_pay_demo.git

 

cd ali_pay_demo

 

cp .env.example .env   (.env 里请配置相关  appid 、公钥和私钥)go run main.go

避坑

  • viper 加载 envfile 配置文件时, 参考如下:

    1

    2

    3

    4

    5

    6

    viper.SetConfigName(".env")viper.SetConfigType("env"//  env 类型viper.AddConfigPath("./")if err := viper.ReadInConfig(); err != nil {

      fmt.Println(err)

      if _, ok := err.(viper.ConfigFileNotFoundError); ok {

          fmt.Println(".env 配置文件未找到")

          return

          }}

    1

    官方文档原文: viper.SetConfigType("json") // because there is no file extension in a stream of bytes,  supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop", "env", "dotenv"

更多golang相关技术文章,请访问golang教程栏目!

阅读剩余部分

相关阅读 >>

总结 go 的数据类型

手撸golang spring ioc/aop 之1

手撸golang 结构型设计模式 组合模式

学习sync.map的总结

golang实现http代理服务器

手撸golang etcd raft协议之8

markdown 自定义的思考

golang项目如何部署到linux服务器

golang中定义不定长数组的方法

关于go的&和*的区别以及应用场景

更多相关阅读请进入《golang》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...