mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
26
.github/workflows/go.yml
vendored
26
.github/workflows/go.yml
vendored
@@ -7,8 +7,21 @@ on:
|
||||
branches: [ master,release-* ]
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.15.x]
|
||||
name: golangci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.31
|
||||
build:
|
||||
name: Build
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
redis:
|
||||
@@ -21,20 +34,11 @@ jobs:
|
||||
ports:
|
||||
- 11211:11211
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ^1.13
|
||||
id: go
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v1
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.26
|
||||
|
||||
|
||||
- name: Test
|
||||
run: go test -v -race ./...
|
||||
|
||||
@@ -11,7 +11,7 @@ linters:
|
||||
- errcheck
|
||||
- funlen
|
||||
- goconst
|
||||
- gocritic
|
||||
# - gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
|
||||
2
cache/cache.go
vendored
2
cache/cache.go
vendored
@@ -2,7 +2,7 @@ package cache
|
||||
|
||||
import "time"
|
||||
|
||||
//Cache interface
|
||||
// Cache interface
|
||||
type Cache interface {
|
||||
Get(key string) interface{}
|
||||
Set(key string, val interface{}, timeout time.Duration) error
|
||||
|
||||
10
cache/memcache.go
vendored
10
cache/memcache.go
vendored
@@ -7,18 +7,18 @@ import (
|
||||
"github.com/bradfitz/gomemcache/memcache"
|
||||
)
|
||||
|
||||
//Memcache struct contains *memcache.Client
|
||||
// Memcache struct contains *memcache.Client
|
||||
type Memcache struct {
|
||||
conn *memcache.Client
|
||||
}
|
||||
|
||||
//NewMemcache create new memcache
|
||||
// NewMemcache create new memcache
|
||||
func NewMemcache(server ...string) *Memcache {
|
||||
mc := memcache.New(server...)
|
||||
return &Memcache{mc}
|
||||
}
|
||||
|
||||
//Get return cached value
|
||||
// Get return cached value
|
||||
func (mem *Memcache) Get(key string) interface{} {
|
||||
var err error
|
||||
var item *memcache.Item
|
||||
@@ -40,7 +40,7 @@ func (mem *Memcache) IsExist(key string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
//Set cached value with key and expire time.
|
||||
// Set cached value with key and expire time.
|
||||
func (mem *Memcache) Set(key string, val interface{}, timeout time.Duration) (err error) {
|
||||
var data []byte
|
||||
if data, err = json.Marshal(val); err != nil {
|
||||
@@ -51,7 +51,7 @@ func (mem *Memcache) Set(key string, val interface{}, timeout time.Duration) (er
|
||||
return mem.conn.Set(item)
|
||||
}
|
||||
|
||||
//Delete delete value in memcache.
|
||||
// Delete delete value in memcache.
|
||||
func (mem *Memcache) Delete(key string) error {
|
||||
return mem.conn.Delete(key)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//Package config 小程序config配置
|
||||
// Package config 小程序config配置
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
)
|
||||
|
||||
//Config config for 小程序
|
||||
// Config config for 小程序
|
||||
type Config struct {
|
||||
AppID string `json:"app_id"` //appid
|
||||
AppSecret string `json:"app_secret"` //appsecret
|
||||
AppID string `json:"app_id"` // appid
|
||||
AppSecret string `json:"app_secret"` // appsecret
|
||||
Cache cache.Cache
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
)
|
||||
|
||||
//Config config for 微信公众号
|
||||
// Config config for 微信公众号
|
||||
type Config struct {
|
||||
AppID string `json:"app_id"` //appid
|
||||
AppSecret string `json:"app_secret"` //appsecret
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package config
|
||||
|
||||
//Config config for pay
|
||||
// Config config for pay
|
||||
type Config struct {
|
||||
AppID string `json:"app_id"`
|
||||
MchID string `json:"mch_id"`
|
||||
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
SignTypeHMACSHA256 = `HMAC-SHA256`
|
||||
)
|
||||
|
||||
//EncryptMsg 加密消息
|
||||
// EncryptMsg 加密消息
|
||||
func EncryptMsg(random, rawXMLMsg []byte, appID, aesKey string) (encrtptMsg []byte, err error) {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
@@ -38,7 +38,7 @@ func EncryptMsg(random, rawXMLMsg []byte, appID, aesKey string) (encrtptMsg []by
|
||||
return
|
||||
}
|
||||
|
||||
//AESEncryptMsg ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId]
|
||||
// AESEncryptMsg ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId]
|
||||
//参考:github.com/chanxuehong/wechat.v2
|
||||
func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphertext []byte) {
|
||||
const (
|
||||
@@ -76,7 +76,7 @@ func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphe
|
||||
return
|
||||
}
|
||||
|
||||
//DecryptMsg 消息解密
|
||||
// DecryptMsg 消息解密
|
||||
func DecryptMsg(appID, encryptedMsg, aesKey string) (random, rawMsgXMLBytes []byte, err error) {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
|
||||
12
util/http.go
12
util/http.go
@@ -52,9 +52,9 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jsonData = bytes.Replace(jsonData, []byte("\\u003c"), []byte("<"), -1)
|
||||
jsonData = bytes.Replace(jsonData, []byte("\\u003e"), []byte(">"), -1)
|
||||
jsonData = bytes.Replace(jsonData, []byte("\\u0026"), []byte("&"), -1)
|
||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003c"), []byte("<"))
|
||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003e"), []byte(">"))
|
||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u0026"), []byte("&"))
|
||||
body := bytes.NewBuffer(jsonData)
|
||||
response, err := http.Post(uri, "application/json;charset=utf-8", body)
|
||||
if err != nil {
|
||||
@@ -75,9 +75,9 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
jsonData = bytes.Replace(jsonData, []byte("\\u003c"), []byte("<"), -1)
|
||||
jsonData = bytes.Replace(jsonData, []byte("\\u003e"), []byte(">"), -1)
|
||||
jsonData = bytes.Replace(jsonData, []byte("\\u0026"), []byte("&"), -1)
|
||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003c"), []byte("<"))
|
||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003e"), []byte(">"))
|
||||
jsonData = bytes.ReplaceAll(jsonData, []byte("\\u0026"), []byte("&"))
|
||||
|
||||
body := bytes.NewBuffer(jsonData)
|
||||
response, err := http.Post(uri, "application/json;charset=utf-8", body)
|
||||
|
||||
Reference in New Issue
Block a user