{"id":37767,"date":"2020-02-26T17:16:51","date_gmt":"2020-02-26T09:16:51","guid":{"rendered":"http:\/\/4563.org\/?p=37767"},"modified":"2020-02-26T17:16:51","modified_gmt":"2020-02-26T09:16:51","slug":"%e6%97%a0%e8%81%8a%e5%9c%a8%e5%ae%b6%ef%bc%8c%e5%86%99%e4%ba%86%e4%b8%aa%e8%b0%83%e7%94%a8v2ray%e6%8e%a5%e5%8f%a3%e7%9a%84demo%ef%bc%8c%e5%90%84%e4%bd%8dmjj%e5%8f%af%e4%bb%a5%e5%8f%82%e8%80%83","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=37767","title":{"rendered":"\u65e0\u804a\u5728\u5bb6\uff0c\u5199\u4e86\u4e2a\u8c03\u7528v2ray\u63a5\u53e3\u7684demo\uff0c\u5404\u4f4dmjj\u53ef\u4ee5\u53c2\u8003"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>king51<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u65e0\u804a\u5728\u5bb6\uff0c\u5199\u4e86\u4e2a\u8c03\u7528v2ray\u63a5\u53e3\u7684demo\uff0c\u5404\u4f4dmjj\u53ef\u4ee5\u53c2\u8003<\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 king51 \u4e8e 2020-2-26 15:53 \u7f16\u8f91 <\/p>\n<p> package main<\/p>\n<p>  import (<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;context&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;fmt&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;github.com\/labstack\/gommon\/log&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;github.com\/satori\/go.uuid&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;google.golang.org\/grpc&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; \/\/ proxy\u7ba1\u7406\u670d\u52a1<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; proxymanService &quot;v2ray.com\/core\/app\/proxyman\/command&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u7edf\u8ba1\u670d\u52a1<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; statsService &quot;v2ray.com\/core\/app\/stats\/command&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;v2ray.com\/core\/common\/protocol&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;v2ray.com\/core\/common\/serial&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &quot;v2ray.com\/core\/proxy\/vmess&quot;<br \/>  )<\/p>\n<p>  \/\/ \u6dfb\u52a0\u7528\u6237<br \/>  func addUser(conn *grpc.ClientConn) error {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; client := proxymanService.NewHandlerServiceClient(conn)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; userUUID := uuid.NewV4().String() \/\/\u4f7f\u7528UUID\u5e93\u751f\u6210\u4e00\u4e2aUUID<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; resp, err := client.AlterInbound(context.Background(), &amp;proxymanService.AlterInboundRequest{<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tag: &quot;proxy&quot;, \/\/ \u8981\u6dfb\u52a0\u7528\u6237\u7684tag\uff0c\u76ee\u524d\u53ea\u652f\u6301vmess\u534f\u8bae<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Operation: serial.ToTypedMessage(&amp;proxymanService.AddUserOperation{<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; User: &amp;protocol.User{<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Level: 0,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;\/\/ \u7528\u6237\u7b49\u7ea7<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Email: &quot;usermail@qq.com&quot;, \/\/ \u7528\u6237\u90ae\u7bb1\uff0c\u5220\u9664\u548c\u7edf\u8ba1\u8981\u7528\u5230<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Account: serial.ToTypedMessage(&amp;vmess.Account{<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Id:&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;userUUID,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;\/\/\u7528\u6237UUID<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AlterId:&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 4,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; \/\/ \u989d\u5916ID<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SecuritySettings: &amp;protocol.SecurityConfig{Type: protocol.SecurityType_AUTO}, \/\/ \u5b89\u5168\u8bbe\u7f6e\uff0cauto\u4e3a\u81ea\u52a8\u5224\u65ad\u52a0\u5bc6\u534f\u8bae<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }),<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }),<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; })<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return err<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(resp)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(userUUID)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; return nil<br \/>  }<\/p>\n<p>  \/\/ \u5220\u9664\u7528\u6237<br \/>  func removeUser(conn *grpc.ClientConn) error {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; client := proxymanService.NewHandlerServiceClient(conn)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; resp, err := client.AlterInbound(context.Background(), &amp;proxymanService.AlterInboundRequest{<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tag: &quot;proxy&quot;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Operation: serial.ToTypedMessage(&amp;proxymanService.RemoveUserOperation{<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Email: &quot;usermail@qq.com&quot;, \/\/ \u7528\u6237\u90ae\u7bb1\u5730\u5740<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }),<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; })<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return err<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(resp)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; return nil<br \/>  }<\/p>\n<p>  \/\/ \u83b7\u53d6\u7528\u6237\u6d41\u91cf<br \/>  func queryUserTraffic(conn *grpc.ClientConn) error {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; client := statsService.NewStatsServiceClient(conn)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; resp, err := client.QueryStats(context.Background(), &amp;statsService.QueryStatsRequest{<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/*<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user&gt;&gt;&gt;&gt;&gt;&gt;traffic&gt;&gt;&gt;uplink<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u7279\u5b9a\u7528\u6237\u7684\u4e0a\u884c\u6d41\u91cf\uff0c\u5355\u4f4d\u5b57\u8282\u3002<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user&gt;&gt;&gt;&gt;&gt;&gt;traffic&gt;&gt;&gt;downlink<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u7279\u5b9a\u7528\u6237\u7684\u4e0b\u884c\u6d41\u91cf\uff0c\u5355\u4f4d\u5b57\u8282\u3002<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inbound&gt;&gt;&gt;&gt;&gt;&gt;traffic&gt;&gt;&gt;uplink<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u7279\u5b9a\u5165\u7ad9\u4ee3\u7406\u7684\u4e0a\u884c\u6d41\u91cf\uff0c\u5355\u4f4d\u5b57\u8282\u3002<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inbound&gt;&gt;&gt;&gt;&gt;&gt;traffic&gt;&gt;&gt;downlink<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u7279\u5b9a\u5165\u7ad9\u4ee3\u7406\u7684\u4e0b\u884c\u6d41\u91cf\uff0c\u5355\u4f4d\u5b57\u8282\u3002<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *\/<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pattern: &quot;user&quot;, \/\/ \u7b5b\u9009\u7528\u6237\u8868\u8fbe\u5f0f<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Reset_:false,\/\/ \u67e5\u8be2\u5b8c\u6210\u540e\u662f\u5426\u91cd\u7f6e\u6d41\u91cf<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; })<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return err<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u83b7\u53d6\u8fd4\u56de\u503c\u4e2d\u7684\u6d41\u91cf\u4fe1\u606f<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; stat := resp.GetStat()<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5bf9\u5176\u8fdb\u884c\u904d\u5386\u8f93\u51fa<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; for _, e := range stat {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(e)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; return nil<br \/>  }<\/p>\n<p>  func main() {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u8fde\u63a5grpc\u670d\u52a1<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; conn, err := grpc.Dial(&quot;IP:port&quot;, grpc.WithInsecure())<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; panic(err)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; \/\/err = queryUserTraffic(conn)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; err = addUser(conn)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; \/\/err = removeUser(conn)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.Info(err)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if err = conn.Close(); err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.Info(&quot;\u5173\u95ed\u8fde\u63a5\u5931\u8d25&quot;)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  }<\/p>\n<p>  yc022t\u521d\u5b66go\uff0c\u611f\u89c9\u8fd9\u8bed\u8a00\u633a\u597d\u7528\u554a\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>hasamol7468<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u53ef\u60dc\u4e0d\u662f\u62cd\u9ec4\u76ae\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>king51<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\thasamol7468 \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-2-26 15:50<br \/>  \u53ef\u60dc\u4e0d\u662f\u62cd\u9ec4\u76ae<\/p>\n<p> yc007t php\u6bd5\u7adf\u4e0d\u662f\u8c37\u6b4c\u81ea\u5bb6 \u8c03\u7528grpc\u9ebb\u70e6\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>korbin<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u6d3e\u9ec4\u7247\u5f88\u597d\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>wuxjian<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 wuxjian \u4e8e 2020-2-26 16:02 \u7f16\u8f91 <\/p>\n<p> go error\u5199\u7684\u5f88\u6076\u5fc3,\u6211\u4e5f\u5199\u8fc7\u4e00\u4e9b\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>hasamol7468<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tking51 \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-2-26 15:53<br \/>  php\u6bd5\u7adf\u4e0d\u662f\u8c37\u6b4c\u81ea\u5bb6 \u8c03\u7528grpc\u9ebb\u70e6<\/p>\n<p> \u7684\u786e\uff0c\u4e4b\u524d\u6574\u8fc7\uff0c\u5f88\u5934\u5927\u53ea\u597d\u6574\u4e86\u4e2a\u4e2d\u95f4\u4ef6\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u98ce\u94c3<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tking51 \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-2-26 15:53<br \/>  php\u6bd5\u7adf\u4e0d\u662f\u8c37\u6b4c\u81ea\u5bb6 \u8c03\u7528grpc\u9ebb\u70e6<\/p>\n<p> \u4e5f\u4e0d\u662f\u5f88\u9ebb\u70e6 \u6709grpc\u4e00\u952e\u751f\u6210\u5404\u79cd\u8bed\u8a00\u7684, \u8f6c\u6210php\u548cjs\u4e00\u6837\u7528<br \/>  \u76ee\u524d\u6211\u7528\u7684js\u8c03\u7528\u7684\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>king51 \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u65e0\u804a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/37767"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37767"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/37767\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=37767"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=37767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}