195aff7392c96049d221ec22d359638974a03a87.svn-base 9.5 KB

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