|
@@ -0,0 +1,64 @@
|
|
|
+package rpc
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "log"
|
|
|
+ rpc "net/rpc"
|
|
|
+
|
|
|
+ util "app.yhyue.com/moapp/jybase/common"
|
|
|
+)
|
|
|
+
|
|
|
+type TmplItem struct {
|
|
|
+ Value string `json:"value,omitempty"`
|
|
|
+ Color string `json:"color,omitempty"`
|
|
|
+}
|
|
|
+
|
|
|
+type WxTmplMsg struct {
|
|
|
+ OpenId string //用户id
|
|
|
+ Url string
|
|
|
+ TplId string
|
|
|
+ TmplData map[string]*TmplItem
|
|
|
+}
|
|
|
+
|
|
|
+/*通用的微信发模板消息方法
|
|
|
+ *成功:repl=="Y"
|
|
|
+ */
|
|
|
+func WxSendTmplMsg(address string, p *WxTmplMsg) (bool, error) {
|
|
|
+ defer util.Catch()
|
|
|
+ var repl string
|
|
|
+ client, err := rpc.DialHTTP("tcp", address)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(p.OpenId, err)
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+ defer client.Close()
|
|
|
+ err = client.Call("WeiXinRpc.SendTmplMsg", p, &repl)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(p.OpenId, err)
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+ return repl == "Y", nil
|
|
|
+}
|
|
|
+
|
|
|
+//app推送消息rpc接口
|
|
|
+func AppPush(address string, m map[string]interface{}) bool {
|
|
|
+ defer util.Catch()
|
|
|
+ var repl string
|
|
|
+ client, err := rpc.DialHTTP("tcp", address)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(m, err.Error())
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ defer client.Close()
|
|
|
+ b, err := json.Marshal(m)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(m, err.Error())
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ err = client.Call("Rpc.Push", b, &repl)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(m, err.Error())
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return repl == "y"
|
|
|
+}
|