package com.yidian.shenghuoquan.bdemo.service

import com.yidian.bcommon.services.ZapServiceActionConstants
import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.yac.core.zap.ZapService
import com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import org.json.JSONObject

/**
 * author: yinjiacheng
 * date: 7/30/21 4:27 PM
 * description: C端客户端信息服务
 */
class ClientInfoService : ZapService() {

  override fun onAction(path: String, action: String, params: Any, options: Any, resolver: ResultResolver) {
    when (action) {
      ZapServiceActionConstants.ActionGetUserInfo -> {
        // 获取C端userId、userName、userPhone
        resolver.success(
          JSONObject()
            .put("userId", "510227073302")
            .put("userName", "yjc0314")
            .put("userPhone", "15054298387")
        )
      }
      // 获取C端网络请求公共参数
      ZapServiceActionConstants.ActionGetRequestPublicParameters -> {
        resolver.success(
          JSONObject()
            .put("appid", "merchant-c")
            .put("cv", "1.0.0")
            .put("version", "001000")
            .put("distribution", "official")
            .put("net", "wifi")
            .put("platform", "1")
            .put("device_finger", FtDeviceFingerManager.getDeviceFinger())
            .put(
              "reqid", StringBuilder()
                .append("merchant-c")
                .append('_')
                .append(FtDeviceFingerManager.getDeviceFinger())
                .append('_')
                .append(System.currentTimeMillis())
                .toString()
            )
        )
      }
    }
  }

  override fun onExit() {

  }

  override fun onInit() {

  }
}
