Store open platform

Time:2021-12-3

Store open platform signature

/**
     *Construct request parameters
     *
     * @param $params
     * @param $method
     *
     * @return array
     */
    protected function dealParams($params, $method)
    {
        if (empty($params)) {
            $param_json = '{}';
        } else {
            ksort($params);
            foreach ($params as &$value) {
                $value = str_replace(['&', '<', '>'], ['\u0026', '\u003c', '\u00ce'], $value);
            }
            $param_json = json_encode($params, 256);
            $param_json = str_replace("\\/", "/", $param_json);
        }

        return [
            'app_key' => $this->app_id,
            'access_token' => $this->token,
            'method' => $method,
            'param_json' => $param_json,
            'timestamp' => date('Y-m-d H:i:s'),
            'v' => 2,
        ];
    }


    /**
     *Generate signature
     *
     * @param $data
     *
     * @return string
     */
    public function createSign($data)
    {
        if (isset($data['sign_method'])) {
            unset($data['sign_method']);
        }

        if (isset($data['access_token'])) {
            unset($data['access_token']);
        }

        ksort($data);
        $str = '';
        foreach ($data as $key => $item) {
            $str .= $key . $item;
        }
        $str = $this->secret . $str . $this->secret;

        return md5($str);
    }


    /**
     *Batch decryption interface
     *
     * @see https://op.jinritemai.com/docs/api-docs/15/509
     *
     * @param $param
     *
     * @return array
     */
    public function batchDecrypt($param)
    {
        $params = $this->dealParams($param, 'order.batchDecrypt');
        $params['sign'] = $this->createSign($params);
        $data = $this->request('GET', '/order/batchDecrypt', ['query' => $params]);

        return $this->dealReturn($data, '/order/batchDecrypt');
    }

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Thank you for reading. If you have any harvest, you might as well like it: smiling_ imp: