getInfo(['id' => $id]); if (!empty($info)) { $this->gatewayHost = $info['push_url']; $this->appKey = $info['app_id']; $this->appSecret = $info['app_secret']; $this->config = $info; } else { $this->gatewayHost = addon_url('supply://api/index'); } } public function getConfig() { return $this->config; } /*** * 获取远程商品列表 * @param $data * @return array * @throws \Exception */ public function getGoodsList($data = []) { $return = $this->requestApi('supply.v1.product.lists', $data); $return = json_decode($return, true); return $this->success($return['result']); } /*** * 获取商品详情 * @param $productID * @return array * @throws \Exception */ public function getGoodsInfo($productID) { $data = [ 'itemIds' => $productID ]; if(is_array($productID)){ $data=implode(',',$productID); } $return = $this->requestApi('supply.v1.product.details', $data); $return = json_decode($return, true); return $this->success($return['result']); } /*** * 关注产品 * @param $data * @return array * @throws \Exception */ public function followGoods($productID,$cloudType='') { $data=[ 'itemId' =>$productID, 'cloud_id' =>$cloudType, 'isFollow' =>1, ]; $return = $this->requestApi('supply.v1.product.follow', $data); $return = json_decode($return, true); return $this->success($return['result']); } /*** * 创建订单 * @param $data * @return array * @throws \Exception */ public function createOrderData($data) { $return = $this->requestApi('supply.v1.order.fastCreateOrder', $data); $return = json_decode($return, true); return $this->success($return['result']); } /**** * 发起余额代扣 * @param $data * @return array * @throws \Exception */ public function pBalancePay($data) { $return = $this->requestApi('supply.v1.orderPay.pbalancePay', $data); $return = json_decode($return, true); return $this->success($return['result']); } public function getPayOnlineInfo($data) { $return = $this->requestApi('supply.v1.orderPay.getPay', $data); $return = json_decode($return, true); if ($return['code'] >= 0) { return $this->success($return['result']); }else{ return $return; } } /*** * 获取产品详情 * @param $data * @return array * @throws \Exception */ public function getOrderInfo($data) { $return = $this->requestApi('supply.v1.order.getOrderInfo', $data); $return = json_decode($return, true); return $this->success($return['result']); } /*** * 取消关闭订单 * @param $data * @return void * @throws \Exception */ public function cancelOrder($data){ $return = $this->requestApi('supply.v1.order.cancel', $data); $return = json_decode($return, true); if ($return['code'] >= 0) { return $this->success($return['result']); }else{ return $return; } } /*** * 请求接口 * @param string $api * @param $data * @return array|bool|mixed|string * @throws \Exception */ public function requestApi(string $api, $data = []) { $timestamp = round(microtime(true)); $data['timestamp'] = $timestamp; $data['app_id'] = $this->appKey; $data['app_secret'] = $this->appSecret; $data['method'] = $api; $data['signature'] = $this->getSign($data); // 发起请求 return http($this->gatewayHost, 30, [], array_merge($this->public, $data)); } /*** * 获取签名 * @param $path * @param $postData * @return string */ public function getSign($data) { ksort($data); $content = http_build_query($data); $sign = hash_hmac("sha1", $content, $this->appSecret, true); $signHexWithLowcase = bin2hex($sign); $signHexUppercase = strtoupper($signHexWithLowcase); return $signHexUppercase; } }