package controller

import (
“encoding/json”
“errors”
“fmt”
“extend/helper”
“github.com/bitly/go-simplejson”
“github.com/gin-gonic/gin”
“io/ioutil”
“log”
“net/http”
“sort”
“strings”
“time”
)

type TestController struct{}

//发布礼物配置
func (t *TestController) Index(c *gin.Context) {
result := make(map[string]interface{})
//result[“success”] = true
//result[“data”] = PostForm(c.Request)
//PostTest2(c)
//_, _ = c.GetPostForm(“sign1”)
//result[“postJson”] = PostTest(c.Request)
////result[“postJson2”] = PostTest3(c)
////result[“postJson1”] = Get(c.Request)
////result[“getC”] = getC
////result[“getD”] = d
//result[“Method”] = c.Request.Method
//result[“url”] = c.Request.URL
//result[“Proto”] = c.Request.Proto
//result[“Header”] = c.Request.Header
//result[“Host”] = c.Request.Host
////result[“GetBody”] = c.Request.GetBody
//result[“PostForm”] = c.Request.PostForm
//result[“MultipartForm”] = c.Request.MultipartForm
//result[“Trailer”] = c.Request.Trailer
//result[“RemoteAddr”] = c.Request.RemoteAddr
//result[“RequestURI”] = c.Request.RequestURI
//result[“Response”] = c.Request.Response

//data, err = verifySign(c)
//fmt.Println(data)
//fmt.Println(err)

result, _ = verifySign(c)

helper.Successful(c, result)
}

func verifySign(c *gin.Context) (data map[string]interface{}, err error) {
data = make(map[string]interface{})

req := c.Request
if req.Method == “GET” {
keys := req.URL.Query()
for k, v := range keys {
data[k] = v[0]
}
} else if req.Method == “POST” {
contentType := req.Header.Get(“Content-Type”)
if contentType == “application/x-www-form-urlencoded” {
req.ParseForm()
for k, v := range req.Form {
if len(v) < 1 { continue } data[k] = v[0] } } else if strings.Contains(contentType, "multipart/form-data;") { _ = c.PostForm("sign") for k, v := range req.PostForm { if len(v) < 1 { continue } data[k] = v[0] } } else if contentType == "application/json" { c.BindJSON(&data) } else { err = errors.New("错误的Content-type") } } else { err = errors.New("错误的Method") } return } //Get get请求url参数 func Get(req *http.Request) map[string]string { var result = make(map[string]string) keys := req.URL.Query() for k, v := range keys { result[k] = v[0] } return result } //PostForm 获取postform形式的参数 func PostForm(req *http.Request) map[string]string { //body, _ := ioutil.ReadAll(req.Body) var result = make(map[string]string) req.ParseForm() for k, v := range req.PostForm { if len(v) < 1 { continue } result[k] = v[0] } return result } //PostJson 获取post json参数 func PostJson(req *http.Request, obj interface{}) error { body, err := ioutil.ReadAll(req.Body) if err != nil { return err } err = json.Unmarshal(body, obj) if err != nil { return err } return nil } //Get get请求url参数 func PostTest(req *http.Request) map[string]interface{} { var result = make(map[string]interface{}) body, err := ioutil.ReadAll(req.Body) if err != nil { return nil } err = json.Unmarshal(body, result) if err != nil { return result } return nil } //Get get请求url参数 func PostTest2(c *gin.Context) { json := make(map[string]interface{}) //注意该结构接受的内容 c.BindJSON(&json) log.Printf("%v", &json) } //Get get请求url参数 func PostTest3(c *gin.Context) map[string]interface{} { jsons := make(map[string]interface{}) //注意该结构接受的内容 c.BindJSON(&jsons) cont := jsons["content"].(string) js, err := simplejson.NewJson([]byte(cont)) //反序列化 if err != nil { panic(err.Error()) } fmt.Println(js) return jsons } var AppSecret string = "111" // 验证签名 //func verifySign(c *gin.Context) (map[string]string, error) { // // //appKey = "demo" // //appSecret = "xxx" // //encryptStr = "param_1=xxx&param_2=xxx&ak="+appKey+"&ts=xxx" // //自定义验证规则 // //sn = MD5(appSecret + encryptStr + appSecret) // // // validate appid redirectURI and return stat code scope // //var urlStr string = "https://www.google.com/" // https%3a%2f%2fwww.google.com%2f // //escapeUrl := url.QueryEscape(urlStr) // //fmt.Println("编码:", escapeUrl) // //enEscapeUrl, _ := url.QueryUnescape(escapeUrl) // //fmt.Println("解码:", enEscapeUrl) // // // _ = c.Request.ParseForm() // req := c.Request.Form // debug := strings.Join(c.Request.Form["debug"], "") // sn := strings.Join(c.Request.Form["sn"], "") // ts := strings.Join(c.Request.Form["ts"], "") // // // 验证来源 // // AppSecret = "test" // // if debug == "1" { // var currentUnix int64 = 534243132 //自己写的 // req.Set("ts", strconv.FormatInt(currentUnix, 10)) // res := map[string]string{ // "ts": strconv.FormatInt(currentUnix, 10), // "sn": createSign(req), // } // return res, nil // } // abcd := "10" // // 验证过期时间 // timestamp := time.Now().Unix() // exp, _ := strconv.ParseInt(abcd, 10, 64) // tsInt, _ := strconv.ParseInt(ts, 10, 64) // if tsInt > timestamp || timestamp-tsInt >= exp {
// return nil, errors.New(“ts Error”)
// }
// // 验证签名
// if sn == “” || sn != createSign(req) {
// return nil, errors.New(“sn Error”)
// }
// return nil, nil
//}

// 创建签名
func createSign(params map[string]interface{}) (string, map[string]interface{}) {
params[“appSecret”] = AppSecret

_, haveSign := params[“sign”]
if haveSign {
delete(params, “sign”)
}

_, haveTimestamp := params[“timestamp”]
if !haveTimestamp {
params[“appSecret”] = time.Now().Unix()
}

sign := helper.Md5(helper.Md5(createEncryptChildStr(params)) + AppSecret)
delete(params, “appSecret”)

return sign, params
}

func createEncryptChildStr(params map[string]interface{}) string {
var key []string
var str = “”
for k := range params {
key = append(key, k)
}
sort.Strings(key)
for i := 0; i < len(key); i++ { val := params[key[i]] if i == 0 { str = fmt.Sprintf("%v=%v", key[i], val) } else { str = str + fmt.Sprintf("&%v=%v", key[i], val) } } return str }

alias pull=”git pull”
alias pullr=”git pull -r”
alias commit=”git commit”
alias push=”git push”
alias branch=”git branch”
alias check=”git checkout”
alias st=”git status”
alias rig=”cd D:/WWW/xx”


            //usort 更适合处理
            usort($list,function ($a,$b){
                return $a['original_price'] == $b['original_price'] && $a['desc'] > $b['desc'];
            });

//            $count = count($list);
//            for ($k = 1; $k < $count; $k++) {
//                for ($i = 0; $i < $count - $k; $i++) {
//                    if (isset($list[$i + 1])) {
//                        if ($list[$i]['original_price'] == $list[$i + 1]['original_price'] && $list[$i]['desc'] > $list[$i + 1]['desc']) {
//                            $temp = $list[$i];
//                            $list[$i] = $list[$i + 1];
//                            $list[$i + 1] = $temp;
//                        }
//                    }
//                }
//            }

或者session没有可写权限

主要答案有修改runtime目录权限,还有关闭debug。其实这两个是共通的,tp5的默认log目录在runtime里面,并且tp5 默认打开debug的情况下生成日志。

所以目录权限不足,会导致500报错,应该是文件在写入的时候,没有权限导致,但是我的业务流程却是正常执行,说明tp5并没有把日志写入失败作为异常抛出,却改变了它的状态码。所以导致了数据正常返回,但是状态码却离奇变成了500。