Exemple #1
0
func Init() {
	dbConnectionString := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", content.DBUser, content.DBPassword, content.DBAddress, content.DBPort, content.DBSchema)
	dbt, err := sql.Open("mysql", dbConnectionString)
	utils.Panic(err)
	err = dbt.Ping()
	utils.Panic(err)
	db = dbt
	log.Debug("Init db finished")
}
/*保存订单,如果没有该订单会创建新的订单,并返回新的订单号*/
func SaveOrder(order model.Order) (orderId int) {
	result, err := db.Exec(INSERT_ORDER, order.CoOrderId, order.UserId, order.PlayerId, order.GameId, order.ServerId, order.Amount, order.PayType, order.ProductId, order.ProductCount, order.ExtData, order.SdkType, order.Source, order.OrderTime, order.PayTime, order.OrderStatus, order.PayStatus, order.SdkInfo)
	utils.Panic(err)
	if num, _ := result.RowsAffected(); num <= 0 {
		panic(fmt.Sprintf("Save order[%+v] to db error", order))
	}
	idF, err := result.LastInsertId()
	orderId = int(idF)
	utils.Panic(err)
	order.Id = orderId

	cache.SetD(getOrderKey(order.Id), order)
	return
}
Exemple #3
0
func (s360 SDK360) Init(configpath string) {
	log.Debug("[Load]load 360 sdk config start")
	file, err := os.Open(configpath)
	if err != nil {
		log.Debug("[ERROR]360SDK Configuration File Not Found")
		return
	}
	decoder := json.NewDecoder(file)
	err = decoder.Decode(&s360)
	utils.Panic(err)
	defer file.Close()
	log.Debug("[Load]load 360 sdk config end")
}
Exemple #4
0
func startNotifyListener(sdk *SDKCharger) {
	if (*sdk).GetListenPath() == "" || (*sdk).GetListenPort() <= 0 {
		return
	}
	pathStr := fmt.Sprintf("/%s", (*sdk).GetListenPath())
	portStr := fmt.Sprintf(":%d", (*sdk).GetListenPort())
	http.HandleFunc(pathStr, func(w http.ResponseWriter, r *http.Request) {
		defer func() {
			if x := recover(); x != nil {
			}
		}()
		bytes := make([]byte, 1024)
		n, err := r.Body.Read(bytes)
		utils.Panic(err)
		bodyBytes := bytes[:n]
		rOrder := (*sdk).ConfirmNotify(w, bodyBytes)
		schan.SendPayMessage(rOrder)
	})
	http.ListenAndServe(portStr, nil)
}