You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.0 KiB
45 lines
1.0 KiB
package jpush
|
|
|
|
import (
|
|
rsa2 "crypto/rsa"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"git.oa00.com/go/rsa"
|
|
)
|
|
|
|
var authorization string
|
|
var jpushPrivateKey *rsa2.PrivateKey
|
|
|
|
// InitJpush @Title 初始化插件
|
|
func InitJpush(appkey, secret, privateKey string) (err error) {
|
|
authorization = base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", appkey, secret)))
|
|
jpushPrivateKey, err = rsa.ParsePrivateKey(privateKey, rsa.PKCS8)
|
|
if err != nil {
|
|
return errors.New("私钥错误")
|
|
}
|
|
return err
|
|
}
|
|
|
|
// @Title 接口调用
|
|
func exec(url, action string, data interface{}) ([]byte, error) {
|
|
jsonData, err := json.Marshal(&data)
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
return request(post, url+action, string(jsonData), map[string]string{
|
|
"Authorization": "Basic " + authorization,
|
|
"Content-Type": "application/json",
|
|
})
|
|
}
|
|
|
|
// @Title 解密
|
|
func decrypt(data string) ([]byte, error) {
|
|
decodeString, err := base64.StdEncoding.DecodeString(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return rsa.RsaDecrypt(decodeString, jpushPrivateKey)
|
|
}
|