get($mall_id); $model->app_key = $config['app_key']; $model->timestamp = time(); $model->sign = self::sign($model->toArray(), $config['secret_key']); // 生成签名 return $model; } public static function sign(array $data, $secret) { if (isset($data['sign'])) unset($data['sign']); foreach ($data as &$datum) { if (is_string($datum)) { $datum = trim($datum); } } ksort($data); $query = http_build_query($data); $query .= "&secret=$secret"; return strtoupper(md5(strtoupper($query))); } /** * 执行请求 * @param RequestInterface $request * @param ModelInterface $model * @param int $mall_id * @return array * @throws \Exception */ public static function send(RequestInterface $request, ModelInterface $model, int $mall_id) { $mall_id1 = SettingService::getMasterMall(); $resp = $request->send(self::packCommonParams($model, $mall_id1)); if (!empty($resp->getError())) throw new \Exception($resp->getError()); $res = $resp->toArray(); if (!isset($res['status']) || $res['status'] != 200) { QiShangTongError::setData([ 'mall_id' => $mall_id, 'post' => $model->toArray(), 'content' => !is_array($res) ? [$res] : $res, 'route' => $request->getRoute(), ]); // throw new \Exception($res['message']); return $res['message']; } return $res['data'] ?? []; } }