41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
"honoka-chan/encrypt"
|
|
"honoka-chan/model"
|
|
"honoka-chan/tools"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
func AwardSet(ctx *gin.Context) {
|
|
req := gjson.Parse(ctx.PostForm("request_data"))
|
|
pref := tools.UserPref{
|
|
AwardID: int(req.Get("award_id").Int()),
|
|
}
|
|
_, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
|
|
CheckErr(err)
|
|
awardResp := model.AwardSetResp{
|
|
ResponseData: []interface{}{},
|
|
ReleaseInfo: []interface{}{},
|
|
StatusCode: 200,
|
|
}
|
|
resp, err := json.Marshal(awardResp)
|
|
CheckErr(err)
|
|
|
|
nonce := ctx.GetInt("nonce")
|
|
nonce++
|
|
|
|
ctx.Header("user_id", ctx.GetString("userid"))
|
|
ctx.Header("authorize", fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", time.Now().Unix(), ctx.GetString("token"), nonce, ctx.GetString("userid"), ctx.GetInt64("req_time")))
|
|
ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSA_Sign_SHA1(resp, "privatekey.pem")))
|
|
|
|
ctx.String(http.StatusOK, string(resp))
|
|
}
|