12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package servers
- import (
- . "app.yhyue.com/moapp/jybase/api"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
- "fmt"
- "github.com/SKatiyar/qr"
- "jy-docs/config"
- "log"
- "net/url"
- )
- type Share struct {
- *xweb.Action
- shareUrl xweb.Mapper `xweb:"/share/url"` //地址分享
- shareImg xweb.Mapper `xweb:"/share/img"` //链接分享
- }
- func (share *Share) ShareUrl() {
- userId := common.ObjToString(share.GetSession("userId"))
- rData, errMsg := func() (interface{}, error) {
- docId := share.GetString("docId") //分享地址
- return map[string]interface{}{
- "url": getDocShareUrl(userId, docId),
- }, nil
- }()
- if errMsg != nil {
- log.Printf("%s Share err:%s\n", errMsg.Error(), userId)
- }
- share.ServeJson(NewResult(rData, errMsg))
- }
- func (share *Share) ShareImg() {
- userId := common.ObjToString(share.GetSession("userId"))
- docId := share.GetString("docId") //分享地址
- data := getDocShareUrl(userId, docId)
- w := share.ResponseWriter
- w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- w.Header().Set("Pragma", "no-cache")
- w.Header().Set("Expires", "0")
- w.Header().Set("Content-Type", "image/png")
- r, _ := qr.Encode(data, qr.M)
- _, _ = w.Write(r.PNG())
- }
- func getDocShareUrl(userId, docId string) string {
- enUserId := encrypt.SE.Encode2Hex(userId)
- toHref := url.QueryEscape(fmt.Sprintf("/page_docs_app/details/%s?from=%s", docId, enUserId)) //关注跳转页面
- unHref := url.QueryEscape(fmt.Sprintf("/swordfish/about?from=%s", enUserId)) //为关注跳转页面
- log.Println(fmt.Sprintf(config.JyDocsAppConfig.ShareUrl+"?toHref=%s&unHref=%s", toHref, unHref))
- return fmt.Sprintf(config.JyDocsAppConfig.ShareUrl+"?toHref=%s&unHref=%s", toHref, unHref)
- }
|