2023年8月

一、升级前准备

以下是tp6.1.x升级到tp8.0.x的步骤,如果你目前版本是tp6.0.x的,请先将期升级到tp6.1.x切记!!

6.0升级到6.1版本
由于安全性原因,6.1版本移除核心对think-filesystem库的依赖,因此6.0版本升级至6.1版本后,需要单独安装`topthink/think-filesystem`库。

二、查看PHP的版本,tp8要求php >= 8.0

1、查看php版本:

liuhongdi@lhdpc:~$ /usr/local/soft/php8/bin/php --version
PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

当前版本是 8.1.1 ,显然符合条件

2、查看当前项止的thinkphp版本:

liuhongdi@lhdpc:/data/php/tpapibase$ php think version
v6.1.0

三、升级ThinkPHP开始

1、升级原项目到可用的最新版本:

liuhongdi@lhdpc:/data/php/tpapibase$ composer update topthink/framework
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Upgrading topthink/framework (v6.1.1 => v6.1.4)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading topthink/framework (v6.1.4)
  - Upgrading topthink/framework (v6.1.1 => v6.1.4): Extracting archive
Generating autoload files
> @php think service:discover
Succeed!
> @php think vendor:publish
File /data/php/tpapibase/config/trace.php exist!
Succeed!
4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
liuhongdi@lhdpc:/data/php/tpapibase$ php think version
v6.1.4

可以看到升级完成后版本是v6.1.4

2、修改composer.json

"require": {
        "php": ">=8.0.0",
        "topthink/framework": "^8.0",
        "topthink/think-orm": "^3.0",
        "topthink/think-filesystem": "^2.0"
    },
    "require-dev": {
        "symfony/var-dumper": ">=4.2",
        "topthink/think-trace":"^1.0"
    },

对require需要用到的库的版本调整,我的配置版本号如上,

“topthink/think-filesystem”: “^2.0”, 这一行是我手动添加上的,

说明:这些版本号是从哪里来的?

用下面的命令新创建一个thinkphp8项目,从composer.json中就看到了

liuhongdi@lhdpc:/data/php$ composer create-project topthink/think tp8

3、删除composer.lock

liuhongdi@lhdpc:/data/php/tpapibase$ rm composer.lock

4、升级前查看当前各库的版本:

liuhongdi@lhdpc:/data/php/tpapibase$ composer show
firebase/php-jwt          v6.3.1  A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
psr/container             1.1.2   Common Container Interface (PHP FIG PSR-11)
psr/http-message          1.0.1   Common interface for HTTP messages
psr/log                   1.1.4   Common interface for logging libraries
psr/simple-cache          1.0.1   Common interfaces for simple caching
symfony/polyfill-mbstring v1.27.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72    v1.27.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php80    v1.27.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/var-dumper        v4.4.47 Provides mechanisms for walking through any arbitrary PHP variable
topthink/framework        v6.1.4  The ThinkPHP Framework.
topthink/think-helper     v3.1.6  The ThinkPHP6 Helper Package
topthink/think-orm        v2.0.56 think orm
topthink/think-trace      v1.5    thinkphp debug trace

5、升级:

liuhongdi@lhdpc:/data/php/tpapibase$ composer install
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 14 installs, 0 updates, 0 removals
  - Locking firebase/php-jwt (v6.8.0)
  - Locking league/flysystem (2.5.0)
  - Locking league/mime-type-detection (1.11.0)
  - Locking psr/container (2.0.2)
  - Locking psr/http-message (1.1)
  - Locking psr/log (3.0.0)
  - Locking psr/simple-cache (3.0.0)
  - Locking symfony/polyfill-mbstring (v1.27.0)
  - Locking symfony/var-dumper (v6.3.0)
  - Locking topthink/framework (v8.0.1)
  - Locking topthink/think-filesystem (v2.0.2)
  - Locking topthink/think-helper (v3.1.6)
  - Locking topthink/think-orm (v3.0.11)
  - Locking topthink/think-trace (v1.6)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 3 installs, 6 updates, 2 removals
  - Downloading league/mime-type-detection (1.11.0)
  - Downloading psr/container (2.0.2)
  - Downloading symfony/var-dumper (v6.3.0)
  - Downloading psr/simple-cache (3.0.0)
  - Downloading psr/log (3.0.0)
  - Downloading topthink/think-orm (v3.0.11)
  - Downloading topthink/framework (v8.0.1)
  - Downloading league/flysystem (2.5.0)
  - Downloading topthink/think-filesystem (v2.0.2)
  - Removing symfony/polyfill-php80 (v1.27.0)
  - Removing symfony/polyfill-php72 (v1.27.0)
  - Installing league/mime-type-detection (1.11.0): Extracting archive
  - Upgrading psr/container (1.1.2 => 2.0.2): Extracting archive
  - Upgrading symfony/var-dumper (v4.4.47 => v6.3.0): Extracting archive
  - Upgrading psr/simple-cache (1.0.1 => 3.0.0): Extracting archive
  - Upgrading psr/log (1.1.4 => 3.0.0): Extracting archive
  - Upgrading topthink/think-orm (v2.0.61 => v3.0.11): Extracting archive
  - Upgrading topthink/framework (v6.1.4 => v8.0.1): Extracting archive
  - Installing league/flysystem (2.5.0): Extracting archive
  - Installing topthink/think-filesystem (v2.0.2): Extracting archive
2 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
> @php think service:discover
Succeed!
> @php think vendor:publish
File /data/php/tpapibase/config/trace.php exist!
Succeed!
4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

6、查看升级后的版本:

liuhongdi@lhdpc:/data/php/tpapibase$ composer show
firebase/php-jwt           v6.8.0  A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
league/flysystem           2.5.0   File storage abstraction for PHP
league/mime-type-detection 1.11.0  Mime-type detection for Flysystem
psr/container              2.0.2   Common Container Interface (PHP FIG PSR-11)
psr/http-message           1.1     Common interface for HTTP messages
psr/log                    3.0.0   Common interface for logging libraries
psr/simple-cache           3.0.0   Common interfaces for simple caching
symfony/polyfill-mbstring  v1.27.0 Symfony polyfill for the Mbstring extension
symfony/var-dumper         v6.3.0  Provides mechanisms for walking through any arbitrary PHP variable
topthink/framework         v8.0.1  The ThinkPHP Framework.
topthink/think-filesystem  v2.0.2  The ThinkPHP6.1 Filesystem Package
topthink/think-helper      v3.1.6  The ThinkPHP6 Helper Package
topthink/think-orm         v3.0.11 the PHP Database&ORM Framework
topthink/think-trace       v1.6    thinkphp debug trace

7、用php命令查看版本:

liuhongdi@lhdpc:/data/php/tpapibase$ php think version
v8.0.0


最后:

需要注意的是,与之相关的扩展也需要一同更新,比如:composer require topthink/think-view否则会出现报错,如:Call to undefined method....

转自:https://www.cnblogs.com/architectforest/p/17584818.html

不同的签名验签代码,对密钥格式有不同的要求:

比如JAVA一般使用PKCS8格式的密钥,其他语言一般使用PKCS1格式的密钥。

区分小技巧:

开头为"-----BEGIN PRIVATE KEY-----"的密钥格式为PKCS8,
开头为"-----BEGIN RSA PRIVATE KEY-----"的密钥格式为PKCS1

1、数据库连接改为 mysqli
2、connect.php文件里常量 MAGIC_QUOTES_GPC改为如下

define('MAGIC_QUOTES_GPC', version_compare(PHP_VERSION, '5.6.40') > 0 ? false : function_exists('get_magic_quotes_gpc')&&get_magic_quotes_gpc());

3、关闭所以错误报告

注意:
7.5新版安装前改以下文件即可
e/class/connect.php

define('MAGIC_QUOTES_GPC',function_exists('get_magic_quotes_gpc')&&get_magic_quotes_gpc());

改为:

define('MAGIC_QUOTES_GPC',(ini_get('magic_quotes_gpc') == 1) ? true : false);

说明:get_magic_quotes_gpc()php5.4版之后已废除了。

注意三点:

1、交叉编译,要把我的 go 代码编译为 window 执行的文件
2、编译 html 等静态文件到 exe 文件中
3、启动 window 的浏览器

package main
import (
    _ "embed"
    "log"
    "net"
    "net/http"

    "github.com/gin-gonic/gin"
    "github.com/skratchdot/open-golang/open"
)
// 这里不能有空格
//go:embed templates/transaction.html
var content []byte

func main() {
    l, err := net.Listen("tcp", "localhost:3000")
    if err != nil {
        log.Fatal(err)
    }
    r := SetRouter()

    // 使用第三方的包打开chrome
    open.RunWith("http://localhost:3000/transaction", "chrome")
    // Start the blocking server loop
    http.Serve(l, r)
}

func SetRouter() *gin.Engine {
    r := gin.Default()
    // 显示发起交易页面
    r.GET("/transaction", func(c *gin.Context) {
        c.Data(http.StatusOK, "text/html", content)
    })
    return r
}

交叉编译

Linux 下编译 Mac 和 Windows 64 位可执行程序

CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

Mac 下编译 Linux 和 Windows 64 位可执行程序

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

Windows 下编译,依次执行如下命令

SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build -o goblog

通过如下命令可查看 Go 支持 OS 和平台列表:

go tool dist list
aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
freebsd/arm64
illumos/amd64
ios/amd64
ios/arm64
js/wasm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
.
.
.
windows/386
windows/amd64
windows/arm
windows/arm64

参考编辑:https://learnku.com/articles/70273?#reply275739

本人 MacOS系统如下所示:
QQ20230822-093612@2x.png

按照Wails安装步骤时,出现“zsh: command not found: wails”的问题,于是Goolge搜索并找到如下的解决方案:

https://github.com/wailsapp/wails/issues/2046

解决办法在https://github.com/wailsapp/wails/issues/2046#issuecomment-1376535844

On my MacOs Ventura:
Installed go => it is installed to "/usr/local/go"
Installed wails => it is installed in "~go/bin/wails"
Result: "zsh: command not found: wails"
QuickFix for me: sudo cp ~/go/bin/wails /usr/local/go/bin/

其实就这一句话:sudo cp ~/go/bin/wails /usr/local/go/bin/

Fyne一款golang的桌面,对中文支持不够友好,解决办法:
1、环境变量FYNE_FONT=ttf文件路径。
2、代码设置环境变量,如下:

func init(){
    os.Setenv("FYNE_FONT","./yahei.ttf")
}

注意,上面两种办法任一种都可以。

const (
    MININT64 = -922337203685477580
    MAXINT64 = 9223372036854775807
)
 
 
func Max(nums... int64) int64 {
    var maxNum int64 = MININT64
    for _, num := range nums {
        if num > maxNum {
            maxNum = num
        }
    }
    return maxNum
}
 
 
 
 
func Min(nums... int64) int64 {
    var minNum int64 = MAXINT64
    for _, num := range nums {
        if num < minNum {
            minNum = num
        }
    }
    return minNum 
}
 
 
 
func Sum(nums... int64) int64 {
    var sumNum int64 = 0
    for _, num := range nums {
            sumNum += num
    }
    return sumNum 
}

以上是对整形的实现,浮点型需要使用math.Max包下的函数更为科学严谨。

package main

import (
    "context"
    "github.com/wechatpay-apiv3/wechatpay-go/core"
    "github.com/wechatpay-apiv3/wechatpay-go/core/option"
    "github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
    "github.com/wechatpay-apiv3/wechatpay-go/utils"
    "log"
    "time"
)

func main() {

    var (
        mchID                      string = "xxxx"                               // 商户号
        mchCertificateSerialNumber string = "xxxxx" // 商户证书序列号
        mchAPIv3Key                string = "xxxxxx"         // 商户APIv3密钥
    )

    // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
    mchPrivateKey, err := utils.LoadPrivateKeyWithPath("./apiclient_key.pem")
    if err != nil {
        log.Fatal("load merchant private key error")
    }

    ctx := context.Background()
    // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
    opts := []core.ClientOption{
        option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
    }
    client, err := core.NewClient(ctx, opts...)
    if err != nil {
        log.Printf("new wechat pay client err:%s", err)
    }

    svc := native.NativeApiService{Client: client}
    resp, result, err := svc.Prepay(ctx,
        native.PrepayRequest{
            Appid:       core.String("xxxxxxx"),
            Mchid:       core.String("1650242918"),
            Description: core.String("Image形象店-深圳腾大-QQ公仔"),
            OutTradeNo:  core.String("1217752501201407033233368018"),
            TimeExpire:  core.Time(time.Now()),
            Attach:      core.String("自定义数据说明"),
            NotifyUrl:   core.String("https://www.weixin.qq.com/wxpay/pay.php"),
            GoodsTag:    core.String("WXG"),
            //LimitPay:      []string{"LimitPay_example"},
            SupportFapiao: core.Bool(false),
            Amount: &native.Amount{
                Currency: core.String("CNY"),
                Total:    core.Int64(1),
            },
            Detail: &native.Detail{
                CostPrice: core.Int64(608800),
                GoodsDetail: []native.GoodsDetail{native.GoodsDetail{
                    GoodsName:        core.String("iPhoneX 256G"),
                    MerchantGoodsId:  core.String("ABC"),
                    Quantity:         core.Int64(1),
                    UnitPrice:        core.Int64(828800),
                    WechatpayGoodsId: core.String("1001"),
                }},
                InvoiceId: core.String("wx123"),
            },
            SettleInfo: &native.SettleInfo{
                ProfitSharing: core.Bool(false),
            },
            SceneInfo: &native.SceneInfo{
                DeviceId:      core.String("013467007045764"),
                PayerClientIp: core.String("14.23.150.211"),
                StoreInfo: &native.StoreInfo{
                    Address:  core.String("广东省深圳市南山区科技中一道10000号"),
                    AreaCode: core.String("440305"),
                    Id:       core.String("0001"),
                    Name:     core.String("腾讯大厦分店"),
                },
            },
        },
    )

    if err != nil {
        log.Println("\n用我了")
        // 处理错误
        log.Printf("call Prepay err:%s", err)
    } else {
        log.Println("\n正确的结果为:")
        // 处理返回结果
        log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
    }
}

注意修改商户相关参数。