base_edb_lib.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. package data
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/data_manage"
  6. "eta/eta_mobile/models/data_manage/response"
  7. "eta/eta_mobile/utils"
  8. "fmt"
  9. "io/ioutil"
  10. "net/http"
  11. "strings"
  12. )
  13. // AddEdbData 新增指标数据
  14. func AddEdbData(source int, edbCode, frequency string) (resp *models.BaseResponse, err error) {
  15. param := make(map[string]interface{})
  16. param["EdbCode"] = edbCode
  17. param["Source"] = source
  18. param["Frequency"] = frequency
  19. urlStr := ``
  20. switch source {
  21. case utils.DATA_SOURCE_THS:
  22. urlStr = "ths/add"
  23. case utils.DATA_SOURCE_WIND:
  24. urlStr = "wind/add"
  25. case utils.DATA_SOURCE_PB:
  26. urlStr = "pb/add"
  27. case utils.DATA_SOURCE_PB_FINANCE:
  28. urlStr = "pb_finance/add"
  29. case utils.DATA_SOURCE_MANUAL:
  30. urlStr = "manual/add"
  31. case utils.DATA_SOURCE_LZ:
  32. urlStr = "lz/add"
  33. case utils.DATA_SOURCE_YS:
  34. urlStr = "smm/add"
  35. case utils.DATA_SOURCE_GL:
  36. urlStr = "mysteel/add"
  37. case utils.DATA_SOURCE_ZZ:
  38. urlStr = "zz/add"
  39. case utils.DATA_SOURCE_DL:
  40. urlStr = "dl/add"
  41. case utils.DATA_SOURCE_SH:
  42. urlStr = "sh/add"
  43. case utils.DATA_SOURCE_CFFEX:
  44. urlStr = "cffex/add"
  45. case utils.DATA_SOURCE_SHFE:
  46. urlStr = "shfe/add"
  47. case utils.DATA_SOURCE_GIE:
  48. urlStr = "gie/add"
  49. case utils.DATA_SOURCE_LT:
  50. urlStr = "lt/add"
  51. case utils.DATA_SOURCE_COAL:
  52. urlStr = "coal/add"
  53. case utils.DATA_SOURCE_GOOGLE_TRAVEL:
  54. urlStr = "google_travel/add"
  55. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  56. urlStr = "mysteel_chemical/add"
  57. case utils.DATA_SOURCE_EIA_STEO:
  58. urlStr = "eia_steo/add"
  59. case utils.DATA_SOURCE_COM_TRADE:
  60. urlStr = "com_trade/add"
  61. case utils.DATA_SOURCE_SCI:
  62. urlStr = "sci/add"
  63. case utils.DATA_SOURCE_BAIINFO:
  64. urlStr = "baiinfo/add"
  65. case utils.DATA_SOURCE_NATIONAL_STATISTICS:
  66. urlStr = "national_statistics/add"
  67. case utils.DATA_SOURCE_FUBAO:
  68. urlStr = "fubao/add"
  69. case utils.DATA_SOURCE_GFEX:
  70. urlStr = "gz/add"
  71. case utils.DATA_SOURCE_ICPI:
  72. urlStr = "icpi/add"
  73. case utils.DATA_SOURCE_SCI_HQ:
  74. urlStr = "sci_hq/add"
  75. default:
  76. edbSource := data_manage.EdbSourceIdMap[source]
  77. if edbSource != nil {
  78. urlStr = edbSource.EdbAddMethod
  79. }
  80. }
  81. if urlStr == "" {
  82. err = fmt.Errorf("未实现该指标的刷新接口,请联系管理员")
  83. return
  84. }
  85. resp, err = postRefreshEdbData(param, urlStr)
  86. return
  87. }
  88. // AddEdbData 新增指标数据
  89. func AddEdbDataWindWsd(source int, stockCode, edbCode string) (resp *models.BaseResponse, err error) {
  90. param := make(map[string]interface{})
  91. param["EdbCode"] = edbCode
  92. param["StockCode"] = stockCode
  93. param["Source"] = source
  94. urlStr := `wind/wsd/add`
  95. if urlStr == "" {
  96. err = fmt.Errorf("未实现该指标的刷新接口,请联系管理员")
  97. return
  98. }
  99. resp, err = postRefreshEdbData(param, urlStr)
  100. return
  101. }
  102. // AddEdbDataThsDs 新增指标数据
  103. func AddEdbDataThsDs(source int, stockCode, edbCode string) (resp *models.BaseResponse, err error) {
  104. param := make(map[string]interface{})
  105. param["EdbCode"] = edbCode
  106. param["StockCode"] = stockCode
  107. param["Source"] = source
  108. urlStr := `ths/ds/add`
  109. if urlStr == "" {
  110. err = fmt.Errorf("未实现该指标的刷新接口,请联系管理员")
  111. return
  112. }
  113. resp, err = postRefreshEdbData(param, urlStr)
  114. return
  115. }
  116. type AddPredictEdbDataResponse struct {
  117. Ret int
  118. Msg string
  119. ErrMsg string
  120. ErrCode string
  121. Data data_manage.AddEdbInfoResp
  122. Success bool `description:"true 执行成功,false 执行失败"`
  123. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  124. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  125. }
  126. // EdbCalculateSaveMultiResponse 批量计算返回值
  127. type EdbCalculateSaveMultiResponse struct {
  128. Ret int
  129. Msg string
  130. ErrMsg string
  131. ErrCode string
  132. Data data_manage.BatchEdbInfoCalculateBatchSaveResp
  133. Success bool `description:"true 执行成功,false 执行失败"`
  134. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  135. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  136. }
  137. // SaveBasePredictEdbData 新增/编辑预测指标运算
  138. func SaveBasePredictEdbData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  139. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict/save", lang)
  140. err = json.Unmarshal(resultByte, &resp)
  141. if err != nil {
  142. return
  143. }
  144. return
  145. }
  146. type PredictRuleCalculateByNineRespResponse struct {
  147. Ret int
  148. Msg string
  149. ErrMsg string
  150. ErrCode string
  151. Data response.PredictRuleCalculateByNineResp
  152. Success bool `description:"true 执行成功,false 执行失败"`
  153. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  154. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  155. }
  156. // PredictCalculateByNinePreview 预测指标动态环差演算
  157. func PredictCalculateByNinePreview(RuleConfigReqStr, lang string) (resp *PredictRuleCalculateByNineRespResponse, err error) {
  158. _, resultByte, err := postAddEdbData(RuleConfigReqStr, "predict/calculate_by_nine/preview", lang)
  159. err = json.Unmarshal(resultByte, &resp)
  160. if err != nil {
  161. return
  162. }
  163. return
  164. }
  165. // SavePredictEdbData 新增/编辑预测指标运算
  166. func SavePredictEdbData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  167. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict_calculate/save", lang)
  168. err = json.Unmarshal(resultByte, &resp)
  169. if err != nil {
  170. return
  171. }
  172. return
  173. }
  174. // BatchSavePredictEdbData 新增/编辑 预测指标运算(同比、同差)
  175. func BatchSavePredictEdbData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  176. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict_calculate/batch/save", lang)
  177. if err != nil {
  178. return
  179. }
  180. err = json.Unmarshal(resultByte, &resp)
  181. if err != nil {
  182. return
  183. }
  184. return
  185. }
  186. // RefreshEdbData 刷新指标数据
  187. func RefreshEdbData(edbInfoId, source, subSource int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
  188. param := make(map[string]interface{})
  189. param["EdbCode"] = edbCode
  190. param["EdbInfoId"] = edbInfoId
  191. param["StartDate"] = startDate
  192. param["Source"] = source
  193. urlStr := ``
  194. switch source {
  195. case utils.DATA_SOURCE_THS:
  196. switch subSource {
  197. case utils.DATA_SUB_SOURCE_DATE:
  198. urlStr = "ths/ds/refresh"
  199. case utils.DATA_SUB_SOURCE_HIGH_FREQUENCY:
  200. urlStr = "ths/hf/edb/refresh"
  201. default:
  202. urlStr = "ths/refresh"
  203. }
  204. case utils.DATA_SOURCE_WIND:
  205. if subSource == 0 {
  206. urlStr = "wind/refresh"
  207. } else {
  208. urlStr = "wind/wsd/refresh"
  209. }
  210. case utils.DATA_SOURCE_PB:
  211. urlStr = "pb/refresh"
  212. case utils.DATA_SOURCE_PB_FINANCE:
  213. urlStr = "pb_finance/refresh"
  214. case utils.DATA_SOURCE_MANUAL:
  215. urlStr = "manual/refresh"
  216. case utils.DATA_SOURCE_LZ:
  217. urlStr = "lz/refresh"
  218. case utils.DATA_SOURCE_YS:
  219. urlStr = "smm/refresh"
  220. case utils.DATA_SOURCE_GL:
  221. urlStr = "mysteel/refresh"
  222. case utils.DATA_SOURCE_ZZ:
  223. urlStr = "zz/refresh"
  224. case utils.DATA_SOURCE_DL:
  225. urlStr = "dl/refresh"
  226. case utils.DATA_SOURCE_SH:
  227. urlStr = "sh/refresh"
  228. case utils.DATA_SOURCE_CFFEX:
  229. urlStr = "cffex/refresh"
  230. case utils.DATA_SOURCE_SHFE:
  231. urlStr = "shfe/refresh"
  232. case utils.DATA_SOURCE_GIE:
  233. urlStr = "gie/refresh"
  234. case utils.DATA_SOURCE_LT:
  235. urlStr = "lt/refresh"
  236. case utils.DATA_SOURCE_COAL:
  237. urlStr = "coal/refresh"
  238. case utils.DATA_SOURCE_GOOGLE_TRAVEL:
  239. urlStr = "google_travel/refresh"
  240. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  241. urlStr = "mysteel_chemical/refresh"
  242. case utils.DATA_SOURCE_EIA_STEO:
  243. urlStr = "eia_steo/refresh"
  244. case utils.DATA_SOURCE_PREDICT:
  245. urlStr = "predict/refresh"
  246. case utils.DATA_SOURCE_COM_TRADE:
  247. urlStr = "com_trade/refresh"
  248. case utils.DATA_SOURCE_SCI:
  249. urlStr = "sci/refresh"
  250. case utils.DATA_SOURCE_BAIINFO:
  251. urlStr = "baiinfo/refresh"
  252. case utils.DATA_SOURCE_STOCK_PLANT:
  253. urlStr = "stock_plant/refresh"
  254. case utils.DATA_SOURCE_NATIONAL_STATISTICS:
  255. urlStr = "national_statistics/refresh"
  256. case utils.DATA_SOURCE_FUBAO:
  257. urlStr = "fubao/refresh"
  258. case utils.DATA_SOURCE_GFEX:
  259. urlStr = "gz/refresh"
  260. case utils.DATA_SOURCE_ICPI:
  261. urlStr = "icpi/refresh"
  262. case utils.DATA_SOURCE_SCI_HQ:
  263. urlStr = "sci_hq/refresh"
  264. default:
  265. edbSource := data_manage.EdbSourceIdMap[source]
  266. if edbSource != nil {
  267. urlStr = edbSource.EdbRefreshMethod
  268. }
  269. }
  270. if urlStr == "" {
  271. err = fmt.Errorf(fmt.Sprint("source:", source, ";未实现该指标的刷新接口,请联系管理员"))
  272. return
  273. }
  274. resp, err = postRefreshEdbData(param, urlStr)
  275. return
  276. }
  277. // RefreshEdbCalculateData 刷新普通计算指标数据请求
  278. func RefreshEdbCalculateData(edbInfoId int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
  279. param := make(map[string]interface{})
  280. param["EdbCode"] = edbCode
  281. param["EdbInfoId"] = edbInfoId
  282. param["StartDate"] = startDate
  283. resp, err = postRefreshEdbData(param, "calculate/refresh")
  284. return
  285. }
  286. // RefreshPredictEdbCalculateData 刷新 预测计算指标 数据请求
  287. func RefreshPredictEdbCalculateData(edbInfoId int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
  288. param := make(map[string]interface{})
  289. param["EdbCode"] = edbCode
  290. param["EdbInfoId"] = edbInfoId
  291. param["StartDate"] = startDate
  292. resp, err = postRefreshEdbData(param, "predict_calculate/refresh")
  293. return
  294. }
  295. // AddEdbCalculateData 新增 累计值转月-同比值-同差等计算新增
  296. func AddEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  297. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/add", lang)
  298. err = json.Unmarshal(resultByte, &resp)
  299. if err != nil {
  300. return
  301. }
  302. return
  303. }
  304. // EditEdbCalculateData 编辑 累计值转月-同比值-同差等计算新增
  305. func EditEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  306. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/edit", lang)
  307. err = json.Unmarshal(resultByte, &resp)
  308. if err != nil {
  309. return
  310. }
  311. return
  312. }
  313. // BatchSaveEdbCalculateData 新增 累计值转月-同比值-同差等计算新增
  314. func BatchSaveEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  315. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/save", lang)
  316. err = json.Unmarshal(resultByte, &resp)
  317. if err != nil {
  318. return
  319. }
  320. return
  321. }
  322. // BatchEditEdbCalculateData 编辑 累计值转月-同比值-同差等计算新增
  323. func BatchEditEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  324. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/edit", lang)
  325. err = json.Unmarshal(resultByte, &resp)
  326. if err != nil {
  327. return
  328. }
  329. return
  330. }
  331. // BatchSaveEdbCalculateMultiData 批量新增 累计值转月-同比值-同差等计算新增
  332. func BatchSaveEdbCalculateMultiData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *EdbCalculateSaveMultiResponse, err error) {
  333. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/save/multi", lang)
  334. err = json.Unmarshal(resultByte, &resp)
  335. if err != nil {
  336. return
  337. }
  338. return
  339. }
  340. // BatchEditEdbCalculateMultiData 批量编辑 累计值转月-同比值-同差等计算新增
  341. func BatchEditEdbCalculateMultiData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *EdbCalculateSaveMultiResponse, err error) {
  342. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/edit/multi", lang)
  343. err = json.Unmarshal(resultByte, &resp)
  344. if err != nil {
  345. return
  346. }
  347. return
  348. }
  349. //// EditEdbCalculateData 修改计算指标数据请求
  350. //func EditEdbCalculateData(edbInfoCalculateBatchSaveReqStr string) (resp *models.BaseResponse, err error) {
  351. // resp, _, err = postAddEdbData(edbInfoCalculateBatchSaveReqStr, "batch/save")
  352. // return
  353. //}
  354. // ExecPythonCode 执行python代码
  355. func ExecPythonCode(pythonCode string) (resp *models.BaseResponse, err error) {
  356. param := make(map[string]interface{})
  357. param["PythonCode"] = pythonCode
  358. urlStr := `/python/exec`
  359. resp, err = postRefreshEdbData(param, urlStr)
  360. return
  361. }
  362. // AddPythonEdbData 新增python指标
  363. func AddPythonEdbData(param, lang string) (resp *models.BaseResponse, err error) {
  364. urlStr := ``
  365. urlStr = "python/add"
  366. resp, _, err = postAddEdbData(param, urlStr, lang)
  367. return
  368. }
  369. // EditPythonEdbData 编辑python指标
  370. func EditPythonEdbData(param, lang string) (resp *models.BaseResponse, err error) {
  371. urlStr := ``
  372. urlStr = "python/edit"
  373. resp, _, err = postAddEdbData(param, urlStr, lang)
  374. return
  375. }
  376. // SaveAdjustEdbInfo 保存数据调整指标
  377. func SaveAdjustEdbInfo(param, lang string) (resp *models.BaseResponse, err error) {
  378. urlStr := ``
  379. urlStr = "calculate/adjust/save"
  380. resp, _, err = postAddEdbData(param, urlStr, lang)
  381. return
  382. }
  383. // ResetCustomAnalysisData 重置自定义表格的数据
  384. func ResetCustomAnalysisData(reqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  385. _, resultByte, err := postAddEdbData(reqStr, "calculate/custom_analysis/reset", lang)
  386. err = json.Unmarshal(resultByte, &resp)
  387. if err != nil {
  388. return
  389. }
  390. return
  391. }
  392. // CalculateComputeCorrelationResp 拟合残差计算相关性的值返回
  393. type CalculateComputeCorrelationResp struct {
  394. Ret int
  395. Msg string
  396. ErrMsg string
  397. ErrCode string
  398. Data string
  399. Success bool `description:"true 执行成功,false 执行失败"`
  400. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  401. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  402. }
  403. // CalculateComputeCorrelation 拟合残差计算相关性的值
  404. func CalculateComputeCorrelation(edbInfoCalculateBatchSaveReqStr, lang string) (resp *CalculateComputeCorrelationResp, err error) {
  405. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/compute_correlation", lang)
  406. err = json.Unmarshal(resultByte, &resp)
  407. if err != nil {
  408. return
  409. }
  410. return
  411. }
  412. // PredictCalculateComputeCorrelation 拟合残差计算相关性的值(预测指标)
  413. func PredictCalculateComputeCorrelation(edbInfoCalculateBatchSaveReqStr, lang string) (resp *CalculateComputeCorrelationResp, err error) {
  414. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict_calculate/compute_correlation", lang)
  415. err = json.Unmarshal(resultByte, &resp)
  416. if err != nil {
  417. return
  418. }
  419. return
  420. }
  421. // BaseCalculateResp 拟合残差计算相关性的值返回
  422. type BaseCalculateResp struct {
  423. Ret int
  424. Msg string
  425. ErrMsg string
  426. ErrCode string
  427. Data BaseCalculateDataResp
  428. Success bool `description:"true 执行成功,false 执行失败"`
  429. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  430. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  431. }
  432. // BaseCalculateDataResp
  433. // @Description: 基础计算的返回结果
  434. type BaseCalculateDataResp struct {
  435. DataMap map[string]float64
  436. DateList []string
  437. }
  438. // BaseCalculate 基础计算
  439. func BaseCalculate(param, lang string) (resp *BaseCalculateResp, err error) {
  440. urlStr := "calculate/base"
  441. _, resultByte, err := postAddEdbData(param, urlStr, lang)
  442. err = json.Unmarshal(resultByte, &resp)
  443. if err != nil {
  444. return
  445. }
  446. return
  447. }
  448. // AddBaseEdbInfo 新增基础指标
  449. func AddBaseEdbInfo(addBaseEdbInfoReqStr string, source, subSource int, lang string) (resp *AddPredictEdbDataResponse, err error) {
  450. urlStr := ``
  451. switch source {
  452. case utils.DATA_SOURCE_BUSINESS:
  453. urlStr = "business_index/add"
  454. default:
  455. edbSource := data_manage.EdbSourceIdMap[source]
  456. if edbSource != nil {
  457. urlStr = edbSource.EdbRefreshMethod
  458. }
  459. }
  460. if urlStr == "" {
  461. err = fmt.Errorf(fmt.Sprint("source:", source, ";未实现该指标的刷新接口,请联系管理员"))
  462. return
  463. }
  464. _, resultByte, err := postAddEdbData(addBaseEdbInfoReqStr, urlStr, lang)
  465. if err != nil {
  466. return
  467. }
  468. err = json.Unmarshal(resultByte, &resp)
  469. return
  470. }
  471. // postRefreshEdbData 刷新指标数据
  472. func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *models.BaseResponse, err error) {
  473. postUrl := utils.EDB_LIB_URL + urlStr
  474. postData, err := json.Marshal(param)
  475. if err != nil {
  476. return
  477. }
  478. result, err := HttpPost(postUrl, string(postData), utils.ZhLangVersion, "application/json")
  479. if err != nil {
  480. return
  481. }
  482. utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result))
  483. err = json.Unmarshal(result, &resp)
  484. if err != nil {
  485. return
  486. }
  487. return resp, nil
  488. }
  489. // postAddEdbData 新增指标数据
  490. func postAddEdbData(paramStr string, urlStr, lang string) (resp *models.BaseResponse, result []byte, err error) {
  491. postUrl := utils.EDB_LIB_URL + urlStr
  492. result, err = HttpPost(postUrl, paramStr, lang, "application/json")
  493. if err != nil {
  494. return
  495. }
  496. err = json.Unmarshal(result, &resp)
  497. if err != nil {
  498. return
  499. }
  500. return
  501. }
  502. func HttpPost(url, postData, lang string, params ...string) ([]byte, error) {
  503. body := ioutil.NopCloser(strings.NewReader(postData))
  504. client := &http.Client{}
  505. req, err := http.NewRequest("POST", url, body)
  506. if err != nil {
  507. return nil, err
  508. }
  509. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  510. if len(params) > 0 && params[0] != "" {
  511. contentType = params[0]
  512. }
  513. req.Header.Set("Content-Type", contentType)
  514. req.Header.Set("Lang", lang)
  515. req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
  516. resp, err := client.Do(req)
  517. if err != nil {
  518. return nil, err
  519. }
  520. defer resp.Body.Close()
  521. b, err := ioutil.ReadAll(resp.Body)
  522. utils.FileLog.Debug("HttpPost:" + string(b))
  523. return b, err
  524. }