Initial commit: queue workspace
Made-with: Cursor
This commit is contained in:
40
pro_v3.5.1/crmeb/services/delivery/Delivery.php
Normal file
40
pro_v3.5.1/crmeb/services/delivery/Delivery.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace crmeb\services\delivery;
|
||||
|
||||
use crmeb\basic\BaseManager;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* Class Delivery
|
||||
* @package crmeb\services\delivery
|
||||
* @mixin \crmeb\services\delivery\storage\Dada
|
||||
* @mixin \crmeb\services\delivery\storage\Uupt
|
||||
*/
|
||||
class Delivery extends BaseManager
|
||||
{
|
||||
/**
|
||||
* 空间名
|
||||
* @var string
|
||||
*/
|
||||
protected string $namespace = '\\crmeb\\services\\delivery\\storage\\';
|
||||
|
||||
/**
|
||||
* 设置默认
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDefaultDriver()
|
||||
{
|
||||
return Config::get('delivery.default', 'dada');
|
||||
}
|
||||
}
|
||||
380
pro_v3.5.1/crmeb/services/delivery/storage/Dada.php
Normal file
380
pro_v3.5.1/crmeb/services/delivery/storage/Dada.php
Normal file
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------\
|
||||
namespace crmeb\services\delivery\storage;
|
||||
|
||||
use crmeb\basic\BaseDelivery;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Dada extends BaseDelivery
|
||||
{
|
||||
const BASE_URL = 'https://newopen.imdada.cn';
|
||||
|
||||
const ADD_MERCHANT = '/merchantApi/merchant/add';
|
||||
|
||||
const ADD_SHOP = '/api/shop/add';
|
||||
|
||||
const UPDATE_SHOP = '/api/shop/update';
|
||||
|
||||
const GET_CITY_CODE = '/api/cityCode/list';
|
||||
|
||||
const GET_SHOP_DETAIL = '/api/shop/detail';
|
||||
|
||||
const GET_ORDER_PRICE = '/api/order/queryDeliverFee';
|
||||
|
||||
const ADD_ORDER_AFTER_QUERY = '/api/order/addAfterQuery';
|
||||
|
||||
const ADD_ORDER_STSATUS_QUERY = '/api/order/status/query';
|
||||
|
||||
const GET_REASONS = '/api/order/cancel/reasons';
|
||||
|
||||
const CANCEL_ORDER = '/api/order/formalCancel';
|
||||
|
||||
const GET_BALANCE = '/api/balance/query';
|
||||
|
||||
const GET_RECHARGE = '/api/recharge';
|
||||
|
||||
public $config;
|
||||
|
||||
protected array $status = [
|
||||
1 => '待接单',
|
||||
2 => '待取货',
|
||||
3 => '配送中',
|
||||
4 => '已完成',
|
||||
5 => '已取消',
|
||||
8 => '指派单',
|
||||
9 => '妥投异常之物品返回中',
|
||||
10 => '妥投异常之物品返回完成',
|
||||
100 => '骑士到店',
|
||||
1000 => '创建达达运单失败'
|
||||
];
|
||||
public function initialize(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
parent::initialize($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商户
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addMerchant($data)
|
||||
{
|
||||
return $this->sendRequest(self::ADD_MERCHANT, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建门店
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addShop($data)
|
||||
{
|
||||
$parmas[] = $data;
|
||||
return $this->sendRequest(self::ADD_SHOP, $parmas);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新门店
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateShop($data)
|
||||
{
|
||||
$params['origin_shop_id'] = $data['origin_shop_id'];
|
||||
if (isset($data['new_shop_id'])) $params['new_shop_id'] = $data['new_shop_id'];
|
||||
if (isset($data['station_name'])) $params['station_name'] = $data['station_name'];
|
||||
if (isset($data['business'])) $params['business'] = $data['business'];
|
||||
if (isset($data['station_address'])) $params['station_address'] = $data['station_address'];
|
||||
if (isset($data['lng'])) $params['lng'] = $data['lng'];
|
||||
if (isset($data['lat'])) $params['lat'] = $data['lat'];
|
||||
if (isset($data['contact_name'])) $params['contact_name'] = $data['contact_name'];
|
||||
if (isset($data['phone'])) $params['phone'] = $data['phone'];
|
||||
if (isset($data['status'])) $params['status'] = $data['status'];
|
||||
return $this->sendRequest(self::UPDATE_SHOP, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预发布订单
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addOrder($data)
|
||||
{
|
||||
$params = [
|
||||
'deliveryNo' => $data['deliveryNo'],
|
||||
];
|
||||
return $this->sendRequest(self::ADD_ORDER_AFTER_QUERY, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算订单价格
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrderPrice($data)
|
||||
{
|
||||
$params = [
|
||||
'shop_no' => $data['shop_no'],
|
||||
'origin_id' => $data['origin_id'],
|
||||
'city_code' => $data['city_code'],
|
||||
'cargo_price' => $data['cargo_price'],
|
||||
'is_prepay' => $data['is_prepay'],
|
||||
'receiver_name' => $data['receiver_name'],
|
||||
'receiver_address'=> $data['receiver_address'],
|
||||
'callback' => $this->callback_url,
|
||||
'cargo_weight' => $data['cargo_weight'],
|
||||
'receiver_phone' => $data['receiver_phone'],
|
||||
'is_finish_code_needed'=> $data['is_finish_code_needed'],
|
||||
];
|
||||
return $this->sendRequest(self::GET_ORDER_PRICE, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrderDetail($data)
|
||||
{
|
||||
$params['order_id'] = $data['origin_id'];
|
||||
$res = $this->sendRequest(self::ADD_ORDER_STSATUS_QUERY, $params);
|
||||
if($res){
|
||||
$res['status_name'] = $this->status[$res['statusCode']] ?? '';
|
||||
$res['porter_name'] = $this->status[$res['transporterName']] ?? '';
|
||||
$res['porter_phone'] = $this->status[$res['transporterPhone']] ?? '';
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function cancelOrder($data)
|
||||
{
|
||||
$params['order_id'] = $data['origin_id'];
|
||||
$params['cancel_reason'] = $data['cancel_reason'] ?? '无';
|
||||
$params['cancel_reason_id'] = $data['reason'];
|
||||
return $this->sendRequest(self::CANCEL_ORDER, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取充值地址
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRecharge($data =[])
|
||||
{
|
||||
$params = [
|
||||
'amount' => $data['amount'] ?? 100,
|
||||
'category'=> $data['category'] ?? 'PC',
|
||||
];
|
||||
return $this->sendRequest(self::GET_RECHARGE, $params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBalance($data)
|
||||
{
|
||||
$params['category'] = $data['category'] ?? 3;
|
||||
$res = $this->sendRequest(self::GET_BALANCE, $params);
|
||||
return [
|
||||
'deliverBalance' => $res['deliverBalance']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付小费
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addTip($data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消原因
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function reasons($data = '')
|
||||
{
|
||||
$options = $this->sendRequest(self::GET_REASONS, $data);
|
||||
foreach ($options as $option) {
|
||||
$value = $option['id'];
|
||||
$label = $option['reason'];
|
||||
$res[] = compact('value','label');
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取城市信息
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCity($data = '')
|
||||
{
|
||||
$res = $this->sendRequest(self::GET_CITY_CODE, $data);
|
||||
foreach ($res as $item) {
|
||||
$data[] = [
|
||||
'key' => $item['cityName'],
|
||||
'label' => $item['cityName'],
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取门店信息
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getShopDetail($id)
|
||||
{
|
||||
$data = ['origin_shop_id' => $id];
|
||||
return $this->sendRequest(self::GET_SHOP_DETAIL, $data);
|
||||
}
|
||||
|
||||
public function getBusiness()
|
||||
{
|
||||
return [
|
||||
['key' => 1 , 'label' => '食品小吃'],
|
||||
['key' => 2 , 'label' => '饮料'],
|
||||
['key' => 3 , 'label' => '鲜花绿植'],
|
||||
['key' => 5 , 'label' => '其他'],
|
||||
['key' => 8 , 'label' => '文印票务'],
|
||||
['key' => 9 , 'label' => '便利店'],
|
||||
['key' => 13 , 'label' => '水果生鲜'],
|
||||
['key' => 19 , 'label' => '同城电商'],
|
||||
['key' => 20 , 'label' => '医药'],
|
||||
['key' => 21 , 'label' => '蛋糕'],
|
||||
['key' => 24 , 'label' => '酒品'],
|
||||
['key' => 25 , 'label' => '小商品市场'],
|
||||
['key' => 26 , 'label' => '服装'],
|
||||
['key' => 27 , 'label' => '汽修零配'],
|
||||
['key' => 28 , 'label' => '数码家电'],
|
||||
['key' => 29 , 'label' => '小龙虾/烧烤'],
|
||||
['key' => 31 , 'label' => '超市'],
|
||||
['key' => 51 , 'label' => '火锅'],
|
||||
['key' => 53 , 'label' => '个护美妆'],
|
||||
['key' => 55 , 'label' => '母婴'],
|
||||
['key' => 57 , 'label' => '家居家纺'],
|
||||
['key' => 59 , 'label' => '手机'],
|
||||
['key' => 61 , 'label' => '家装'],
|
||||
['key' => 63 , 'label' => '成人用品'],
|
||||
];
|
||||
}
|
||||
|
||||
public function sendRequest($api, $params)
|
||||
{
|
||||
$url = self::BASE_URL . $api;
|
||||
$params = $this->bulidRequestParams($params);
|
||||
$response = $this->httpRequestWithPost($url, $params);
|
||||
$data = $this->getMessage($response);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造请求数据
|
||||
* data:业务参数,json字符串
|
||||
*/
|
||||
public function bulidRequestParams($params)
|
||||
{
|
||||
$requestParams = array();
|
||||
$requestParams['app_key'] = $this->config['app_key'];
|
||||
$requestParams['body'] = json_encode($params);
|
||||
$requestParams['format'] = 'json';
|
||||
$requestParams['v'] = '1.0';
|
||||
$requestParams['source_id'] = $this->config['source_id'];
|
||||
$requestParams['timestamp'] = time();
|
||||
$requestParams['signature'] = $this->_sign($requestParams);
|
||||
return json_encode($requestParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名生成signature
|
||||
*/
|
||||
public function _sign($data)
|
||||
{
|
||||
//1.升序排序
|
||||
ksort($data);
|
||||
//2.字符串拼接
|
||||
$args = "";
|
||||
foreach ($data as $key => $value) {
|
||||
$args .= $key . $value;
|
||||
}
|
||||
$args = $this->config['app_secret'] . $args . $this->config['app_secret'];
|
||||
//3.MD5签名,转为大写
|
||||
$sign = strtoupper(md5($args));
|
||||
return $sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求,POST
|
||||
* @param $url 指定URL完整路径地址
|
||||
* @param $data 请求的数据
|
||||
*/
|
||||
public function httpRequestWithPost($url, $data, $headers = [])
|
||||
{
|
||||
$headers = array(
|
||||
'Content-Type: application/json',
|
||||
);
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 3);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
$resp = curl_exec($curl);
|
||||
$info = curl_getinfo($curl);
|
||||
curl_close($curl);
|
||||
if (isset($info['http_code']) && $info['http_code'] == 200) {
|
||||
return $resp;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
protected function getMessage($json, $message = '未知错误!')
|
||||
{
|
||||
$data = json_decode($json, true);
|
||||
//code=2551 订单创建中
|
||||
if (!in_array($data['code'], [0, 2551])) {
|
||||
isset($data['msg']) && $message = $data['msg'];
|
||||
if ($data['errorCode'] == 7718) {
|
||||
foreach ($data['result']['failedList'] as $datum) {
|
||||
$message .= ':'.$datum['shopName'].'/'. $datum['msg'].';';
|
||||
}
|
||||
}
|
||||
throw new ValidateException('【达达错误提示】:'.$message);
|
||||
} else {
|
||||
if ($data['status'] == 'success') return $data['result'] ?? $data;
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
418
pro_v3.5.1/crmeb/services/delivery/storage/Uupt.php
Normal file
418
pro_v3.5.1/crmeb/services/delivery/storage/Uupt.php
Normal file
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace crmeb\services\delivery\storage;
|
||||
|
||||
use crmeb\basic\BaseDelivery;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Uupt extends BaseDelivery
|
||||
{
|
||||
//uu跑腿
|
||||
public $config;
|
||||
|
||||
//域名
|
||||
// const BASE_URL = 'http://openapi.test.uupt.com';
|
||||
const BASE_URL = 'https://openapi.uupt.com';
|
||||
|
||||
//发布订单
|
||||
const ADD_ORDER = '/v2_0/addorder.ashx';
|
||||
|
||||
//计算价格
|
||||
const GET_ORDER_PRICE = '/v2_0/getorderprice.ashx';
|
||||
|
||||
//详情
|
||||
const GET_ORDER_DETAIL = '/v2_0/getorderdetail.ashx';
|
||||
|
||||
//充值
|
||||
const GET_RECHARGE = '/v2_0/getrecharge.ashx';
|
||||
|
||||
//取消
|
||||
const CANCEL_ORDER = '/v2_0/cancelorder.ashx';
|
||||
|
||||
//查询门店
|
||||
const GET_SHOP = '/v2_0/getshoplist.ashx';
|
||||
|
||||
//余额
|
||||
const GET_BALANCEDE = '/v2_0/getbalancedetail.ashx';
|
||||
|
||||
//获取城市
|
||||
const GET_CITY = '/v2_0/getcitylist.ashx';
|
||||
|
||||
protected array $status = [
|
||||
1 => '下单成功',
|
||||
3 => '跑男抢单',
|
||||
4 => '已到达',
|
||||
5 => '已取件',
|
||||
6 => '到达目的地',
|
||||
10 => '收件人已收货',
|
||||
-1 => '订单取消'
|
||||
];
|
||||
|
||||
public function initialize(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
parent::initialize($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布订单
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addOrder($data)
|
||||
{
|
||||
$params = [
|
||||
'price_token' => $data['price_token'],
|
||||
'order_price' => $data['total_money'],
|
||||
'balance_paymoney' => $data['need_paymoney'],
|
||||
'receiver' => $data['receiver'],
|
||||
'receiver_phone' => $data['receiver_phone'],
|
||||
'callback_url' => $this->callback_url,
|
||||
'push_type' => '0', //推送方式(0 开放订单,2测试订单)默认传0即可
|
||||
'special_type' => '0',
|
||||
'callme_withtake' => $data['callme_withtake'] ?? '0',
|
||||
'pay_type' => 0,
|
||||
];
|
||||
if ($data['note']) $params['note'] = $data['note'];
|
||||
return $this->sendRequest(self::ADD_ORDER, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算订单价格
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrderPrice($data)
|
||||
{
|
||||
$params = [
|
||||
'from_address' => $data['from_address'],
|
||||
'to_address' => $data['to_address'],
|
||||
'city_name' => $data['city_name'],
|
||||
'goods_type' => $data['goods_type'],
|
||||
'send_type' => '0',
|
||||
'to_lat' => (string)$data['to_lat'],
|
||||
'to_lng' => (string)$data['to_lng'],
|
||||
'from_lat' => (string)$data['from_lat'],
|
||||
'from_lng' => (string)$data['from_lng'],
|
||||
];
|
||||
return $this->sendRequest(self::GET_ORDER_PRICE, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrderDetail($data)
|
||||
{
|
||||
if ($data['order_sn']) $params['origin_id'] = $data['order_sn'];
|
||||
if ($data['order_code']) $params['order_code'] = $data['order_code'];
|
||||
$res = $this->sendRequest(self::GET_ORDER_DETAIL, $params);
|
||||
if ($res) {
|
||||
$res['status_name'] = $this->status[$res['state']] ?? '';
|
||||
$res['porter_name'] = $this->status[$res['driver_name']] ?? '';
|
||||
$res['porter_phone'] = $this->status[$res['driver_mobile']] ?? '';
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function cancelOrder($data)
|
||||
{
|
||||
$params = [
|
||||
'origin_id' => $data['origin_id'],
|
||||
'order_code' => $data['order_code'],
|
||||
'reason' => $data['reason'],
|
||||
];
|
||||
return $this->sendRequest(self::CANCEL_ORDER, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取充值地址
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRecharge($data)
|
||||
{
|
||||
return $this->sendRequest(self::GET_RECHARGE, $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBalance($data)
|
||||
{
|
||||
$res = $this->sendRequest(self::GET_BALANCEDE, $data);
|
||||
return [
|
||||
'deliverBalance' => $res['AccountMoney']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付小费
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addTip($data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取城市信息
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCity($data = [])
|
||||
{
|
||||
$res = $this->sendRequest(self::GET_CITY, $data);
|
||||
foreach ($res['CityList'] as $item) {
|
||||
$data[] = [
|
||||
'key' => $item['CityName'],
|
||||
'label' => $item['CityName'],
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求
|
||||
* @param $api
|
||||
* @param $params
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendRequest($api, $params = [])
|
||||
{
|
||||
$url = self::BASE_URL . $api;
|
||||
$params = $this->bulidRequestParams($params);
|
||||
$response = $this->httpRequestWithPost($url, $params);
|
||||
$data = $this->getMessage($response);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造请求数据
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
*/
|
||||
public function bulidRequestParams(array $params = [])
|
||||
{
|
||||
$params['openid'] = $this->config['open_id'];
|
||||
$params['appid'] = $this->config['app_id'];
|
||||
$params['nonce_str'] = str_replace('-', '', $this->guid());
|
||||
$params['timestamp'] = time();
|
||||
$params['sign'] = $this->_sign($params);
|
||||
$arr = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$arr[] = $key . '=' . $value;
|
||||
}
|
||||
$curlPost = implode('&', $arr);
|
||||
return $curlPost;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成guid
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function guid()
|
||||
{
|
||||
mt_srand((float)microtime() * 10000); //optional for php 4.2.0 and up.
|
||||
$charid = strtoupper(md5(uniqid(rand(), true)));
|
||||
$hyphen = chr(45); // "-"
|
||||
$uuid = substr($charid, 0, 8) . $hyphen
|
||||
. substr($charid, 8, 4) . $hyphen
|
||||
. substr($charid, 12, 4) . $hyphen
|
||||
. substr($charid, 16, 4) . $hyphen
|
||||
. substr($charid, 20, 12);
|
||||
return strtolower(str_replace('-', '', $uuid));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 签名生成sign
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function _sign($data)
|
||||
{
|
||||
ksort($data);
|
||||
$str = '';
|
||||
foreach ($data as $key => $value) {
|
||||
if (!is_null($value)) {
|
||||
$str .= $key . '=' . $value . '&';
|
||||
}
|
||||
}
|
||||
$str .= 'key=' . $this->config['app_key'];
|
||||
$str = mb_strtoupper($str, 'UTF-8');
|
||||
// halt($data,$str);
|
||||
return strtoupper(md5($str));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求,POST
|
||||
* @param $url 指定URL完整路径地址
|
||||
* @param $data 请求的数据
|
||||
*/
|
||||
public function httpRequestWithPost($url, $data)
|
||||
{
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 3);
|
||||
$resp = curl_exec($curl);
|
||||
$info = curl_getinfo($curl);
|
||||
curl_close($curl);
|
||||
return $resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误信息
|
||||
* @param $json
|
||||
* @param $message
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getMessage($json, $message = '未知错误!')
|
||||
{
|
||||
$data = json_decode($json, true);
|
||||
if (!in_array($data['return_code'], ['ok', 'fail'])) {
|
||||
isset($data['return_msg']) && $message = $data['return_msg'];
|
||||
$mes = $message == '未知错误!' ? $this->getCodeMap($data['return_code']) : $message;
|
||||
throw new ValidateException('【UU错误提示】:' . $mes);
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取错误代码
|
||||
* @param string $key 代码
|
||||
* @return String 错误代码与信息
|
||||
*/
|
||||
protected function getCodeMap($key)
|
||||
{
|
||||
$codeMap = [
|
||||
'-101' => '参数格式校验错误',
|
||||
'-102' => 'timestamp错误',
|
||||
'-103' => 'appid无效',
|
||||
'-104' => '签名校验失败',
|
||||
'-105' => 'openid无效',
|
||||
'-199' => '参数格式校验错误',
|
||||
'-1001' => '无法解析起始地',
|
||||
'-1002' => '无法解析目的地',
|
||||
'-1003' => '无法获取订单城市相关信息',
|
||||
'-1004' => '订单小类出现错误',
|
||||
'-1005' => '没有用户信息',
|
||||
'-1006' => '优惠券ID错误',
|
||||
'-2001' => 'price_token无效',
|
||||
'-2002' => 'price_token无效',
|
||||
'-2003' => '收货人电话格式错误',
|
||||
'-2004' => 'special_type错误',
|
||||
'-2005' => 'callme_withtake错误',
|
||||
'-2006' => 'order_price错误',
|
||||
'-2007' => 'balance_paymoney错误',
|
||||
'-2008' => '订单总金额错误',
|
||||
'-2009' => '支付金额错误',
|
||||
'-2010' => '用户不一致',
|
||||
'-2011' => '手机号错误',
|
||||
'-2012' => '不存在绑定关系',
|
||||
'-4001' => '取消原因不能为空',
|
||||
'-4002' => '订单编号无效',
|
||||
'-5001' => '订单编号无效',
|
||||
'-5002' => '订单编号无效',
|
||||
'-5003' => '订单编号无效',
|
||||
'-10001' => '发送频率过快,请稍候重试',
|
||||
'-11001' => '请输入正确的验证码',
|
||||
];
|
||||
$info = isset($codeMap[$key]) ? $codeMap[$key] : false;
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建商户
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addMerchant($data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取门店信息
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function getShopDetail($id)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建门店
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addShop($data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新门店
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateShop($data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBusiness()
|
||||
{
|
||||
return [
|
||||
['key' => 1, 'label' => '美食'],
|
||||
['key' => 2, 'label' => '鲜花'],
|
||||
['key' => 3, 'label' => '蛋糕'],
|
||||
['key' => 4, 'label' => '手机'],
|
||||
['key' => 5, 'label' => '钥匙'],
|
||||
['key' => 6, 'label' => '文件'],
|
||||
['key' => 0, 'label' => '其他'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user