Merge branch 'master' of e.coding.net:rosydev/baseapi

This commit is contained in:
邹宗楠
2022-08-19 11:35:49 +08:00
9 changed files with 90 additions and 25 deletions

View File

@@ -14,8 +14,8 @@ import (
const (
AliPayPublicCertPath = "./config/alipayCertPublicKey_RSA2.crt" // 支付宝公钥证书文件路径
aliPayRootCertPath = "./config/alipayRootCert.crt" // 支付宝根证书文件路径
appCertPath = "./config/appCertPublicKey_2019110769024042.crt" // 应用公钥证书路径
AliPayRootCertPath = "./config/alipayRootCert.crt" // 支付宝根证书文件路径
AppCertPath = "./config/appCertPublicKey_2019110769024042.crt" // 应用公钥证书路径
MinWithdrawalMoney = 50 // 最小提现金额,不用审核
)
@@ -71,7 +71,7 @@ func (a *API) Withdrawal4AliPay(param *WithdrawalParam) (*Withdrawal4AliPayRes,
param.PayeeInfo.IdentityType = "ALIPAY_LOGON_ID"
// 获取证书
appCertSN, aliPayRootCertSN, aliPayPublicCertSN, err := SetCertSnByPath(appCertPath, aliPayRootCertPath, AliPayPublicCertPath)
appCertSN, aliPayRootCertSN, aliPayPublicCertSN, err := SetCertSnByPath(AppCertPath, AliPayRootCertPath, AliPayPublicCertPath)
if err != nil {
return nil, err
}
@@ -94,15 +94,15 @@ func (a *API) Withdrawal4AliPay(param *WithdrawalParam) (*Withdrawal4AliPayRes,
}
// SetCertSnByPath 通过应用公钥证书路径设置 app_cert_sn、alipay_root_cert_sn、alipay_cert_sn
// appCertPath应用公钥证书路径
// aliPayRootCertPath支付宝根证书文件路径
// AppCertPath应用公钥证书路径
// AliPayRootCertPath支付宝根证书文件路径
// aliPayPublicCertPath支付宝公钥证书文件路径
func SetCertSnByPath(appCertPath, aliPayRootCertPath, aliPayPublicCertPath string) (string, string, string, error) {
appCertSn, err := GetCertSN(appCertPath)
func SetCertSnByPath(AppCertPath, AliPayRootCertPath, aliPayPublicCertPath string) (string, string, string, error) {
appCertSn, err := GetCertSN(AppCertPath)
if err != nil {
return "", "", "", fmt.Errorf("get app_cert_sn return err, but alse return alipay client. err: %w", err)
}
rootCertSn, err := GetRootCertSN(aliPayRootCertPath)
rootCertSn, err := GetRootCertSN(AliPayRootCertPath)
if err != nil {
return "", "", "", fmt.Errorf("get alipay_root_cert_sn return err, but alse return alipay client. err: %w", err)
}

View File

@@ -1,10 +1,15 @@
package alipayapi
import "git.rosy.net.cn/baseapi/utils"
import (
"git.rosy.net.cn/baseapi/utils"
)
const (
GrantTypeCode = "authorization_code"
GrantTypeRefresh = "refresh_token"
GrantTypeCode = "authorization_code"
AliPayPublicCertPath2 = "./conf/alipayCertPublicKey_RSA2.crt" // 支付宝公钥证书文件路径
AliPayRootCertPath2 = "./conf/alipayRootCert.crt" // 支付宝根证书文件路径
AppCertPath2 = "./conf/appCertPublicKey_2019110769024042.crt" // 应用公钥证书路径
GrantTypeRefresh = "refresh_token"
)
type TokenInfo struct {
@@ -41,6 +46,16 @@ func (a *API) SystemAuthToken(grantType, code, refreshToken string) (tokenInfo *
if refreshToken != "" {
params["refresh_token"] = refreshToken
}
// 获取证书
appCertSN, aliPayRootCertSN, aliPayPublicCertSN, err := SetCertSnByPath(AppCertPath2, AliPayRootCertPath2, AliPayPublicCertPath2)
if err != nil {
return nil, err
}
params["app_cert_sn"] = appCertSN
params["alipay_public_cert_sn"] = aliPayPublicCertSN
params["alipay_root_cert_sn"] = aliPayRootCertSN
retVal, err := a.AccessAPI("alipay.system.oauth.token", params, nil, false)
if err == nil {
err = utils.Map2StructByJson(retVal, &tokenInfo, false)

View File

@@ -1,6 +1,8 @@
package dingdingapi
import "git.rosy.net.cn/baseapi/utils"
import (
"git.rosy.net.cn/baseapi/utils"
)
type QRCodeUserInfo struct {
Nickname string `json:"nick"`
@@ -22,3 +24,32 @@ func (a *API) GetUserInfoByCode(code string) (userInfo *QRCodeUserInfo, err erro
}
return nil, err
}
type UserGetByUnionIdRsp struct {
ContactType int64 `json:"contact_type"`
UserID string `json:"userid"`
}
//根据union获取用户user_id
func (a *API) GetByUnionID(unionID string) (*UserGetByUnionIdRsp, error) {
//userInfo := new(UserGetByUnionIdRsp)
result, err := a.AccessAPI("topapi/user/getbyunionid", utils.Params2Map("unionid", unionID), nil)
if err != nil {
return nil, err
} else {
tmpResult := result["result"].(map[string]interface{})
return &UserGetByUnionIdRsp{
ContactType: utils.ForceInterface2Int64(tmpResult["contact_type"]),
UserID: utils.Interface2String(tmpResult["userid"]),
}, nil
}
}
//根据user_id获取用户
func (a *API) GetUser(userID string) (map[string]interface{}, error) {
result, err := a.AccessAPI("user/get", utils.Params2Map("userid", userID), nil)
if err != nil {
return nil, err
}
return result, nil
}

View File

@@ -559,6 +559,7 @@ func (a *API) OrderDisagreeRefund(orderID, refuseReason string) (err error) {
return err
}
//售后 同意用户多次部分取消
func (a *API) OrderPartRefund(orderID string, removeSkuList []*RefundSku) (err error) {
_, err = a.AccessAPI("order.manyTimesPartrefund", map[string]interface{}{
"order_id": orderID,

View File

@@ -37,7 +37,7 @@ func TestGatAllFee(t *testing.T) {
DeliveryType: 0,
GoodsValue: 1000,
SendAddress: "四川省成都市金牛区二环北路一段10号万科加州湾V派616",
ReceiveAddress: "北京市北京市朝阳区来广营地区中铁国际城乐享汇大厦3号楼1132",
ReceiveAddress: "北京市北京市朝阳区容达路7号太极产业园",
Type: 0,
Weight: 1,
Length: 100,

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/jx-callback/globals"
"net/http"
"strings"
)
@@ -34,6 +35,7 @@ func (a *API) AccessAPI2(url string, params map[string]interface{}) (retVal map[
if err != nil {
return nil, err
}
globals.SugarLogger.Debug("进入AccessAPI2DATA=================", data)
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, url, strings.NewReader(string(data)))
@@ -48,5 +50,6 @@ func (a *API) AccessAPI2(url string, params map[string]interface{}) (retVal map[
retVal = jsonResult1
return platformapi.ErrLevelSuccess, nil
})
globals.SugarLogger.Debug("我也不知道哪里出错返回一下retVal", retVal)
return retVal, err
}

View File

@@ -8,8 +8,10 @@ const (
GetTiktokOauth = "https://developer.toutiao.com/api/apps/v2/jscode2session" // 获取抖音授权
GetTiktokQrCode = "https://developer.toutiao.com/api/apps/qrcode" // 获取小程序二维码
TiktokAppId = "tta6a1d01c399f264201"
TiktokSecret = "5c08a0465cf0f996af254a03b6c2548defef87ad"
TiktokAppId = "tta6a1d01c399f264201"
TiktokSecret = "5c08a0465cf0f996af254a03b6c2548defef87ad"
TiktokJXDJAppID = "ttaceeda5333d7a7ab01"
tiktokJXDJSecret = "5c8492ec2744fb72bb6cc356983f3cfc317f85d4"
)
// OauthAccessTokenResData access_token
@@ -38,15 +40,17 @@ type OauthAccessTokenRes struct {
// 抖音登录返回值
type TiktokOauthResone struct {
ErrNo int64 `json:"err_no"`
ErrTips string `json:"err_tips"`
Data *struct {
SessionKey string `json:"session_key"`
OpenId string `json:"openid"` // 授权用户唯一标识
AnonymousOpenid string `json:"anonymous_openid"`
Unionid string `json:"unionid"`
Dopenid string `json:"dopenid"`
}
ErrNo int64 `json:"err_no"`
ErrTips string `json:"err_tips"`
Data *TiktokData `json:"data"`
}
type TiktokData struct {
SessionKey string `json:"session_key"`
OpenId string `json:"openid"` // 授权用户唯一标识
AnonymousOpenid string `json:"anonymous_openid"`
Unionid string `json:"unionid"`
Dopenid string `json:"dopenid"`
}
// 预下单

View File

@@ -28,7 +28,14 @@ func TestCode(t *testing.T) {
func TestCode2(t *testing.T) {
a := New("5c08a0465cf0f996af254a03b6c2548defef87ad ", "tta6a1d01c399f264201")
data, err := a.GetTiktokOauth("CCRHRLfkl8kSHXuuZTDWQayoqHVXF2Vl4qrt173jxfWhg6Q1pZCbjRO0TzTGNPZd5vTW8UcjRupxfmEIdM06WSmAjwhvr-Ak_Pg9gJfHfrq2KvLH5eYL4C68BXM")
data, err := a.GetTiktokOauth("tYIYf03MgvPekdeWj91W3RhdzQMCovGG_QugelFswhWiZLdIwMFlMtC7PHZbl-JjrkwaonexoEahd1GDCS6K5jK4W7oegChlysU3kCw72cL965P0MWMyXdO_qeA")
fmt.Println(err)
fmt.Println(data)
}
func TestCode343(t *testing.T) {
a := New("5c8492ec2744fb72bb6cc356983f3cfc317f85d4", "ttaceeda5333d7a7ab01")
data, err := a.GetTiktokOauth("eDpIjQ2VdK4MC8wE9ORO63adZECE8no_yNLXQYPaILyLUXF24K02PNcs84lQeeJn68EQJPIiV6DO5z3vHoqLom4dr4Fy4KMcZK7O4a3yAHK0Vgs9Vc-2u9vLwAg")
fmt.Println(err)
fmt.Println(data)
}

View File

@@ -3,15 +3,18 @@ package tiktok
import (
"errors"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
)
// 获取抖音登录授权2
func (a *API) GetTiktokOauth(code string) (*TiktokOauthResone, error) {
globals.SugarLogger.Debug("初始code=============", code)
tokenReq := make(map[string]interface{}, 3)
tokenReq["appid"] = a.GetAppID()
tokenReq["code"] = code
tokenReq["secret"] = a.GetSecret()
tokenReq["anonymous_code"] = ""
globals.SugarLogger.Debug("输出tokenReq", tokenReq)
result, err := a.AccessAPI2(GetTiktokOauth, tokenReq)
if err != nil {
return nil, err
@@ -25,6 +28,7 @@ func (a *API) GetTiktokOauth(code string) (*TiktokOauthResone, error) {
if oauthAccessToken.ErrNo != 0 {
return nil, errors.New(oauthAccessToken.ErrTips)
}
globals.SugarLogger.Debug("再来输出一下oauthAccessToken", oauthAccessToken)
return oauthAccessToken, nil
}