2 Commits 0bcbf740dd ... d1db09ae99

Tác giả SHA1 Thông báo Ngày
  xyxie d1db09ae99 Merge branch 'feature/eta2.3.4_business_user' into debug 1 ngày trước cách đây
  xyxie 4782e403fd 企查查 1 ngày trước cách đây
4 tập tin đã thay đổi với 169 bổ sung0 xóa
  1. 37 0
      controllers/company_seller.go
  2. 9 0
      routers/commentsRouter.go
  3. 110 0
      services/qichacha.go
  4. 13 0
      utils/common.go

+ 37 - 0
controllers/company_seller.go

@@ -149,3 +149,40 @@ func (this *CompanySellerController) RoadshowFiccList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 企查查模糊查询客户接口
+// @Description 企查查模糊查询客户
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Success 200 {object} services.Result
+// @router /potential/company/qccSearch [get]
+func (this *CompanySellerController) CompanyQCCSearch() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var err error
+	var results []services.Result
+	keyWord := this.GetString("KeyWord")
+	if keyWord != "" {
+		results, err = services.QCCFuzzySearch(keyWord)
+		if err != nil {
+			br.Data = results
+			br.Msg = "获取数据失败," + err.Error()
+			br.Ret = 200
+			br.Success = true
+			return
+		}
+	}
+	br.Data = results
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 9 - 0
routers/commentsRouter.go

@@ -700,6 +700,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanySellerController"] = append(beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanySellerController"],
+        beego.ControllerComments{
+            Method: "CompanyQCCSearch",
+            Router: `/potential/company/qccSearch`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanySellerController"] = append(beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanySellerController"],
         beego.ControllerComments{
             Method: "RoadshowFiccList",

+ 110 - 0
services/qichacha.go

@@ -0,0 +1,110 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"eta/eta_forum_admin/utils"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"strconv"
+	"strings"
+
+	"time"
+)
+
+func GetCompanyInfo() {
+	qccKey := `efd43bfceaa74cf1811079dbcec25c33`
+	qccSecretKey := `2985D128630B085C1BFE8F88630B5DA8`
+	getUrl := `http://api.qichacha.com/ECIV4/Search?key=` + qccKey + `&keyword=913300007125582210`
+
+	timespan := time.Now().Unix()
+	timespanStr := strconv.FormatInt(timespan, 10)
+	token := utils.MD5(qccKey + timespanStr + qccSecretKey)
+	client := &http.Client{}
+	//提交请求
+	reqest, err := http.NewRequest("GET", getUrl, nil)
+	//增加header选项
+	reqest.Header.Add("Token", token)
+	reqest.Header.Add("Timespan", timespanStr)
+
+	if err != nil {
+		panic(err)
+	}
+	//处理返回结果
+	response, _ := client.Do(reqest)
+	defer response.Body.Close()
+
+	body, err := ioutil.ReadAll(response.Body)
+	fmt.Println("body:", string(body))
+	utils.FileLog.Info("%s", string(body))
+}
+
+type QCCResp struct {
+	Paging      Paging   `json:"Paging"`
+	Result      []Result `json:"Result"`
+	Status      string   `json:"Status"`
+	Message     string   `json:"Message"`
+	OrderNumber string   `json:"OrderNumber"`
+}
+type Paging struct {
+	PageSize     int `json:"PageSize"`
+	PageIndex    int `json:"PageIndex"`
+	TotalRecords int `json:"TotalRecords"`
+}
+
+type Result struct {
+	KeyNo      string `json:"KeyNo"`
+	Name       string `json:"Name"`
+	CreditCode string `json:"CreditCode"`
+	StartDate  string `json:"StartDate"`
+	OperName   string `json:"OperName"`
+	Status     string `json:"Status"`
+	No         string `json:"No"`
+}
+
+func QCCFuzzySearch(keyWord string) (results []Result, err error) {
+	qccKey := `49464d73ae1c46e99ad4eff1efe943c1`
+	qccSecretKey := `9DE7E83FFE26789815004C5172503290`
+	getUrl := `http://api.qichacha.com/FuzzySearch/GetList?pageSize=20&key=%s&searchKey=%s `
+	utils.StrFilterNonChinese(&keyWord)
+	finalUrl := fmt.Sprintf(getUrl, qccKey, keyWord)
+	timespan := time.Now().Unix()
+	timespanStr := strconv.FormatInt(timespan, 10)
+	token := utils.MD5(qccKey + timespanStr + qccSecretKey)
+	client := &http.Client{}
+	//提交请求
+	reqest, err := http.NewRequest("GET", finalUrl, nil)
+	if err != nil {
+		utils.FileLog.Info("NewRequest err:" + err.Error())
+		err = errors.New("NewRequest err:" + err.Error())
+		return
+	}
+	//增加header选项
+	reqest.Header.Add("Token", strings.ToUpper(token))
+	reqest.Header.Add("Timespan", timespanStr)
+
+	if err != nil {
+		return
+	}
+	//处理返回结果
+	response, _ := client.Do(reqest)
+	defer response.Body.Close()
+
+	body, err := ioutil.ReadAll(response.Body)
+	var qccResp QCCResp
+	err = json.Unmarshal(body, &qccResp)
+	if err != nil {
+		utils.FileLog.Info("Json Unmarshal err:" + err.Error())
+		err = errors.New("Json Unmarshal err:" + err.Error())
+		return
+	}
+	if qccResp.Status != "200" {
+		utils.FileLog.Info("QCCFuzzySearch err:" + qccResp.Message)
+		err = errors.New("QCCFuzzySearch err:" + qccResp.Message)
+		return
+	} else {
+		results = qccResp.Result
+		return
+	}
+}

+ 13 - 0
utils/common.go

@@ -1359,3 +1359,16 @@ func GetDurationFormatBySecond(sec int) (formatString string) {
 	//}
 	return
 }
+
+// 去除非中文字符串
+func StrFilterNonChinese(src *string) {
+	var hzRegexp = regexp.MustCompile("^[\u4e00-\u9fa5]$")
+	strn := ""
+	for _, c := range *src {
+		if hzRegexp.MatchString(string(c)) {
+			strn += string(c)
+		}
+	}
+
+	*src = strn
+}