互动
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.

160 lines
4.5 KiB

package test
import (
"fmt"
"github.com/chanxuehong/wechat/mch/core"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/logger"
im_service "hudongzhuanjia/services/im"
pay_service "hudongzhuanjia/services/pay"
"hudongzhuanjia/utils"
"math"
"testing"
"time"
)
var openId = "o9XM41s_NN8Y0QK6_MbM-aYMV3TE"
func TestTransfer(t *testing.T) {
res, err := pay_service.Transfer("欧轩互动-转账测试", openId, utils.RandomStr(32), 0.30*100)
fmt.Println(err)
fmt.Printf("%+v\n", res)
}
func TestSendRedPack(t *testing.T) {
res, err := pay_service.SendRedPack("欧轩互动-红包测试", openId,
"你好测试", "tommy",
"哈哈哈哈哈", 1, 1, 1)
fmt.Println(err)
fmt.Printf("%+v\n", res)
}
func TestQueryOrder(t *testing.T) {
//outTradeNo := "Dn13Gl6A6dB6aOae7syqtXSwUvCZ3mta"
outTradeNo := "6PM9n5WDSX47frNfQ9OxWEKe8u6ChBos"
res, err := pay_service.OrderQuery(outTradeNo)
fmt.Println(err)
fmt.Printf("%+v\n", res)
}
func TestClose(t *testing.T) {
pay_service.Close("jGrqipGJdcxQz4uwSTQqrtnJ4rJE6Mx9")
}
func TestTimeExpire(t *testing.T) {
now := time.Now()
t1 := "202004174430"
t2 := core.FormatTime(time.Now())
t3, _ := core.ParseTime(t1)
fmt.Println(t1, t2)
fmt.Println(t1 > t2)
fmt.Println(t3.Unix() > now.Unix())
fmt.Println(t1, t2, core.FormatTime(t3))
fmt.Println(t3.Unix(), now.Unix())
}
func TestSendNotice(t *testing.T) {
for {
err := im_service.SendGroupCustomMessage(4, 118, im_service.NoticeReward,
map[string]interface{}{
"amount": 20.01,
"content": "恭喜你发出",
"timestamp": time.Now().Unix(),
})
fmt.Print(err)
}
}
func TestGenSig(t *testing.T) {
fmt.Print(im.GenSig("admin"))
}
// 地球半径,单位米
const R = 6367000
//const R = 6378.137
func rad(d float64) float64 {
return d * math.Pi / 180.0
}
// lonA, latA分别为A点的纬度和经度
// lonB, latB分别为B点的纬度和经度
// 返回的距离单位为米
func Sphere(lonA, latA, lonB, latB float64) float64 {
c := math.Sin(latA)*math.Sin(latB)*math.Cos(lonA-lonB) + math.Cos(latA)*math.Cos(latB)
return R * math.Acos(c) * math.Pi / 180
}
func TestSphere(t *testing.T) {
lonA, latA := 43.653887, 108.197424
lonB, latB := 42.901128, 107.562718
a := Sphere(lonA, latA, lonB, latB)
fmt.Print(a / 1000.0)
}
func TestMy(t *testing.T) {
a := `SELECT
shop_id ,
shop_name ,
lng ,
lat ,
POWER(lat - 40.05748 , 2) + POWER(lng - 116.30759 , 2) * POWER(COS((lat + 40.05748) / 2) , 2) AS distance
FROM
shop_list
HAVING
distance < 1000
ORDER BY
distance
LIMIT 100;
`
fmt.Print(a)
}
func TestLogger(t *testing.T) {
var i = 0
for {
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
logger.Info("亚洲舞王罗志祥, 多人运动领头羊.")
i++
if i > 10000000000 {
break
}
}
}
func TestSendGroupMessage(t *testing.T) {
err := im_service.SendGroupCustomMessage("admin", 314, im_service.NoticeLotteryDrawRollStart,
map[string]interface{}{
"lottery_draw_ladder_id": 1,
"timestamp": time.Now().Unix(),
"roll_num": 1,
"desc": "开始滚动",
"number": 1,
})
if err != nil {
t.Error(err)
}
}