123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package service
- import (
- "encoding/json"
- "fmt"
- "testing"
- "xiaoniaokuaiyan.com/xiaoniao/config"
- "xiaoniaokuaiyan.com/xiaoniao/pay/wx"
- )
- func TestSendMsg(t *testing.T) {
- wxSrv := &WeixinService{
- Weixin: wx.NewWeixin(config.IniConf.Section("weixin").Key("wx.appid").Value(), config.IniConf.Section("weixin").Key("wx.secret").Value()),
- JsSdk: wx.NewJsSdk(),
- }
- tokenStr, err := wxSrv.GetWXAccessToken("")
- if err != nil {
- t.Fatal(err)
- }
- msg := wx.Message{
- "touser": "onNpDwyL0Tg2n9vYis7mwUBC0VZM",
- "msgtype": "text",
- "text": map[string]string{"content": `测试<a href="http://m.xiaoniaokuaiyan.com">hello world</a>小鸟快验欢迎你`},
- }
- err = wxSrv.Weixin.Send(msg, tokenStr.(string))
- if err != nil {
- t.Fatal(err)
- }
- }
- func TestSendTpl(t *testing.T) {
- wxSrv := &WeixinService{
- Weixin: wx.NewWeixin(config.IniConf.Section("weixin").Key("wx.appid").Value(), config.IniConf.Section("weixin").Key("wx.secret").Value()),
- JsSdk: wx.NewJsSdk(),
- }
- msg := map[string]interface{}{
- "touser": "onNpDwyL0Tg2n9vYis7mwUBC0VZM",
- "template_id": "og_C32ekCtZDIG86FodplOJ-Agj0pYYjTlQLJxt3j_0",
- "url": "http://m.xiaoniaokuaiyan.com",
- "data": map[string]interface{}{
- "first": map[string]interface{}{
- "value": "订单支付成功",
- "color": "#173177",
- },
- "orderMoneySum": map[string]interface{}{
- "value": "200元",
- "color": "#173177",
- },
- "orderProductName": map[string]interface{}{
- "value": "胃幽",
- "color": "#173177",
- },
- "Remark": map[string]interface{}{
- "value": "感谢您使用小鸟快验!",
- "color": "#173177",
- },
- },
- }
- buf, _ := json.Marshal(msg)
- _, err := wxSrv.SendTpl(string(buf), "")
- if err != nil {
- t.Fatal(err)
- }
- }
- func TestScanPay(t *testing.T) {
- wxSrv := &WeixinService{
- Weixin: wx.NewWeixin(config.IniConf.Section("weixin").Key("wx.appid").Value(), config.IniConf.Section("weixin").Key("wx.secret").Value()),
- JsSdk: wx.NewJsSdk(),
- }
- rel, err := wxSrv.ScanPay(map[string]string{
- "ip": "127.0.0.1",
- "device_info": "123",
- "trade_type": "JSAPI",
- "openid": "onNpDwwktNS1lD34UOOQ3Yj0ToZo",
- "total_fee": "100",
- "usefor": "藏医院 核磁",
- })
- if err != nil {
- t.Fatal(err)
- }
- fmt.Println(rel)
- }
- func BenchmarkString(b *testing.B) {
- for i := 0; i < b.N; i++ {
- b.StopTimer()
- b.StartTimer()
- b.ResetTimer()
- }
- }
|