github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/baidupcs/internal/panhome/sign.go (about)

     1  package panhome
     2  
     3  import (
     4  	"github.com/qjfoidnh/Baidu-Login/bdcrypto"
     5  	"github.com/qjfoidnh/BaiduPCS-Go/baidupcs/netdisksign"
     6  	"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/converter"
     7  )
     8  
     9  type (
    10  	// SignRes 签名结果
    11  	SignRes interface {
    12  		Sign() string
    13  		Timestamp() string
    14  	}
    15  
    16  	signRes struct {
    17  		sign      string
    18  		timestamp string
    19  	}
    20  )
    21  
    22  func (sr *signRes) Sign() string {
    23  	return sr.sign
    24  }
    25  func (sr *signRes) Timestamp() string {
    26  	return sr.timestamp
    27  }
    28  
    29  func (ph *PanHome) Signature() (sign SignRes, err error) {
    30  	err = ph.getSignInfo()
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  
    35  	o := netdisksign.Sign2(ph.sign3, ph.sign1)
    36  	signed := bdcrypto.Base64Encode(o)
    37  	return &signRes{
    38  		sign:      converter.ToString(signed),
    39  		timestamp: ph.timestamp,
    40  	}, nil
    41  }