2b80f58778620ce81e8b7a270ad0fb795f1cc4d6.svn-base 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. package util
  2. import (
  3. "bytes"
  4. "encoding/xml"
  5. "fmt"
  6. "io/ioutil"
  7. "net/http"
  8. "strings"
  9. )
  10. type EASLoginInfo struct{
  11. UserName string `json:"userName"`
  12. Password string `json:"password"`
  13. SlnName string `json:"slnName"`
  14. DcName string `json:"dcName"`
  15. Language string `json:"language"`
  16. DbType int32 `json:"dbType"`
  17. }
  18. //webservice tmr暂未使用到
  19. var(
  20. LoginStr = `<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:log="http://login.webservice.bos.kingdee.com">
  21. <soapenv:Header/>
  22. <soapenv:Body>
  23. <log:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  24. <userName xsi:type="xsd:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">userName?</userName>
  25. <password xsi:type="xsd:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">password?</password>
  26. <slnName xsi:type="xsd:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">slnName?</slnName>
  27. <dcName xsi:type="xsd:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">dcName?</dcName>
  28. <language xsi:type="xsd:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">language?</language>
  29. <dbType xsi:type="xsd:int">dbType?</dbType>
  30. </log:login>
  31. </soapenv:Body>
  32. </soapenv:Envelope>
  33. `
  34. LogoutStr = `<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:log="http://login.webservice.bos.kingdee.com">
  35. <soapenv:Header/>
  36. <soapenv:Body>
  37. <log:logout soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  38. <userName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">userName?</userName>
  39. <slnName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">slnName?</slnName>
  40. <dcName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">dcName?</dcName>
  41. <language xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">language?</language>
  42. </log:logout>
  43. </soapenv:Body>
  44. </soapenv:Envelope>
  45. `
  46. InsertPartsStr = `<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.synfacade.modernfarming.eas.kingdee.com">
  47. <soapenv:Header>
  48. <ns1:SessionId
  49. xmlns:ns1="http://login.webservice.bos.kingdee.com">SessionId?
  50. </ns1:SessionId>
  51. </soapenv:Header>
  52. <soapenv:Body>
  53. <web:synMaterial soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  54. <request xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">strJson?</request>
  55. </web:synMaterial>
  56. </soapenv:Body>
  57. </soapenv:Envelope>
  58. `
  59. InsertPartsuselaidStr = `<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:app="http://app.ws.scm.eas.kingdee.com">
  60. <soapenv:Header>
  61. <ns1:SessionId
  62. xmlns:ns1="http://login.webservice.bos.kingdee.com">SessionId?
  63. </ns1:SessionId>
  64. </soapenv:Header>
  65. <soapenv:Body>
  66. <app:importBill soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  67. <billType xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">billType?</billType>
  68. <billDataJSON xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">strJson?</billDataJSON>
  69. <billStatus xsi:type="xsd:int">1</billStatus>
  70. </app:importBill>
  71. </soapenv:Body>
  72. </soapenv:Envelope>
  73. `
  74. )
  75. func eastest(){
  76. sessionid := EASWebServiceLogin()
  77. //EASWebServicInsertParts(sessionid,"{}")
  78. EASWebServicInsertPartsuselaid(sessionid,"{}","007")
  79. //EASWebServiceLogout()
  80. }
  81. type Response struct {
  82. Body rspBody `xml:"Body" json:"body"`
  83. }
  84. type rspBody struct {
  85. Record []rqRecord `xml:"multiRef" json:"multiRef"`
  86. SynMaterialResponse SMReturn `xml:"synMaterialResponse" json:"SynMaterialResponse"`
  87. ImportBillResponse ImportBillResponse `xml:"importBillResponse" json:"importBillResponse"`
  88. }
  89. type ImportBillResponse struct {
  90. ImportBillReturn string `xml:"importBillReturn" json:"importBillReturn"`
  91. }
  92. type SMReturn struct {
  93. SynMaterialReturn string `xml:"synMaterialReturn" json:"synMaterialReturn"`
  94. }
  95. type rqRecord struct {
  96. SessionId string `xml:"sessionId" json:"sessionId"`
  97. }
  98. func EASWebServiceLogin()string{
  99. client := &http.Client{}
  100. resstr := ReplaceStrWebSevice("login","user","kdeas@02","eas","MASM","L2","1","","","")
  101. body := bytes.NewBuffer([]byte(resstr))
  102. req, err := http.NewRequest("POST",
  103. "http://60.174.151.11:6888/ormrpc/services/EASLogin?wsdl",
  104. body,
  105. )
  106. req.Header.Set("Content-Type", "text/xml")
  107. req.Header.Set("SOAPAction", "application/soap+xml")
  108. if err != nil {
  109. // handle error
  110. }
  111. resp, err := client.Do(req)
  112. if err != nil {
  113. fmt.Println(err)
  114. return ""
  115. }
  116. defer resp.Body.Close()
  117. result_body, err := ioutil.ReadAll(resp.Body)
  118. if err != nil {
  119. fmt.Println(err)
  120. return ""
  121. }
  122. v := Response {}
  123. err = xml.Unmarshal([]byte(string(result_body)), &v)
  124. if err != nil {
  125. fmt.Println(err.Error())
  126. }
  127. if len(v.Body.Record)>0{
  128. fmt.Println(v.Body.Record[0].SessionId)
  129. return v.Body.Record[0].SessionId
  130. }
  131. return ""
  132. }
  133. func EASWebServiceLogout(){
  134. client := &http.Client{}
  135. resstr := ReplaceStrWebSevice("logout","user","","eas","MASM","L2","","","","")
  136. body := bytes.NewBuffer([]byte(resstr))
  137. req, err := http.NewRequest("POST",
  138. "http://60.174.151.11:6888/ormrpc/services/EASLogin?wsdl",
  139. body,
  140. )
  141. req.Header.Set("Content-Type", "text/xml")
  142. req.Header.Set("SOAPAction", "application/soap+xml")
  143. if err != nil {
  144. // handle error
  145. }
  146. resp, err := client.Do(req)
  147. if err != nil {
  148. fmt.Println(err)
  149. return
  150. }
  151. defer resp.Body.Close()
  152. result_body, err := ioutil.ReadAll(resp.Body)
  153. if err != nil {
  154. fmt.Println(err)
  155. return
  156. }
  157. fmt.Println(string(result_body))
  158. }
  159. func EASWebServicInsertParts(SessionId,soapencJson string){
  160. client := &http.Client{}
  161. resstr := ReplaceStrWebSevice("InsertParts","","","","","","",SessionId,soapencJson,"")
  162. body := bytes.NewBuffer([]byte(resstr))
  163. req, err := http.NewRequest("POST",
  164. "http://60.174.151.11:6888/ormrpc/services/WSSynMasterDataFacade?wsdl",
  165. body,
  166. )
  167. req.Header.Set("Content-Type", "text/xml")
  168. req.Header.Set("SOAPAction", "application/soap+xml")
  169. if err != nil {
  170. // handle error
  171. }
  172. resp, err := client.Do(req)
  173. if err != nil {
  174. fmt.Println(err)
  175. return
  176. }
  177. defer resp.Body.Close()
  178. result_body, err := ioutil.ReadAll(resp.Body)
  179. if err != nil {
  180. fmt.Println(err)
  181. return
  182. }
  183. v := Response {}
  184. err = xml.Unmarshal([]byte(string(result_body)), &v)
  185. if err != nil {
  186. fmt.Println(err.Error())
  187. }
  188. resmap := make(map[string]string,0)
  189. err = json.Unmarshal([]byte(v.Body.SynMaterialResponse.SynMaterialReturn),&resmap)
  190. if resmap["success"] == "0"{
  191. fmt.Println(resmap["message"])
  192. }
  193. //fmt.Println(string(result_body))
  194. }
  195. func EASWebServicInsertPartsuselaid(SessionId,strJson,billType string){ //billType采购入库单:006 销售出库单:007 其他入库单:008 其他出库单:009 领料出库单:100 生产入库单:101
  196. client := &http.Client{}
  197. resstr := ReplaceStrWebSevice("InsertPartsuselaidStr","","","","","","",SessionId,strJson,billType)
  198. body := bytes.NewBuffer([]byte(resstr))
  199. req, err := http.NewRequest("POST",
  200. "http://60.174.151.11:6888/ormrpc/services/WSSCMWebServiceFacade?wsdl",
  201. body,
  202. )
  203. req.Header.Set("Content-Type", "text/xml")
  204. req.Header.Set("SOAPAction", "application/soap+xml")
  205. if err != nil {
  206. // handle error
  207. }
  208. resp, err := client.Do(req)
  209. if err != nil {
  210. fmt.Println(err)
  211. return
  212. }
  213. defer resp.Body.Close()
  214. result_body, err := ioutil.ReadAll(resp.Body)
  215. if err != nil {
  216. fmt.Println(err)
  217. return
  218. }
  219. v := Response {}
  220. err = xml.Unmarshal([]byte(string(result_body)), &v)
  221. if err != nil {
  222. fmt.Println(err.Error())
  223. }
  224. resmap := make(map[string]interface{},0)
  225. if v.Body.ImportBillResponse.ImportBillReturn != "" {
  226. err = json.Unmarshal([]byte(v.Body.ImportBillResponse.ImportBillReturn),&resmap)
  227. fmt.Println(v.Body.ImportBillResponse.ImportBillReturn)
  228. fmt.Println(len(resmap["billErrors"].([]interface {})))
  229. if resmap["status"] == "2"{
  230. fmt.Println(resmap["msg"])
  231. }
  232. }
  233. }
  234. func ReplaceStrWebSevice(typeIn,userName,password,slnName,dcName,language,dbType,SessionId,strJson,billType string)string{
  235. res := ""
  236. switch typeIn {
  237. case "login":
  238. res = LoginStr
  239. res = strings.ReplaceAll(res,"userName?",userName)
  240. res = strings.ReplaceAll(res,"password?",password)
  241. res = strings.ReplaceAll(res,"slnName?",slnName)
  242. res = strings.ReplaceAll(res,"dcName?",dcName)
  243. res = strings.ReplaceAll(res,"language?",language)
  244. res = strings.ReplaceAll(res,"dbType?",dbType)
  245. case "logout":
  246. res = LogoutStr
  247. res = strings.ReplaceAll(res,"userName?",userName)
  248. res = strings.ReplaceAll(res,"slnName?",slnName)
  249. res = strings.ReplaceAll(res,"dcName?",dcName)
  250. res = strings.ReplaceAll(res,"language?",language)
  251. case "InsertParts":
  252. res = InsertPartsStr
  253. res = strings.ReplaceAll(res,"SessionId?",SessionId)
  254. res = strings.ReplaceAll(res,"strJson?",strJson)
  255. case "InsertPartsuselaidStr":
  256. res = InsertPartsuselaidStr
  257. res = strings.ReplaceAll(res,"SessionId?",SessionId)
  258. res = strings.ReplaceAll(res,"strJson?",strJson)
  259. res = strings.ReplaceAll(res,"billType?",billType)
  260. }
  261. return res
  262. }