154 行
5.1 KiB
PHP
可执行文件
154 行
5.1 KiB
PHP
可执行文件
<?php
|
|
namespace Retail\Controller;
|
|
use Think\Controller;
|
|
//[1.0.92]
|
|
//UU跑腿
|
|
class UudeliveryController extends Controller
|
|
{
|
|
private static $getcode; //获取验证码
|
|
private static $getopenid; //获取openid
|
|
private static $balance; //获取余额详情
|
|
private static $recharge; //充值
|
|
private static $getorderprice; //计算订单价格
|
|
private static $addorder; //下单
|
|
private static $cancelorder; //取消订单
|
|
private static $getorderdetail; //订单详情
|
|
//链接
|
|
public function __construct()
|
|
{
|
|
self::$getcode = 'http://openapi.uupaotui.com/v2_0/binduserapply.ashx';
|
|
self::$getopenid = 'http://openapi.uupaotui.com/v2_0/bindusersubmit.ashx';
|
|
self::$balance = 'http://openapi.uupaotui.com/v2_0/getbalancedetail.ashx';
|
|
self::$recharge = 'http://openapi.uupaotui.com/v2_0/getrecharge.ashx';
|
|
self::$getorderprice ='http://openapi.uupaotui.com/v2_0/getorderprice.ashx';
|
|
self::$addorder = 'http://openapi.uupaotui.com/v2_0/addorder.ashx';
|
|
self::$cancelorder = 'http://openapi.uupaotui.com/v2_0/cancelorder.ashx';
|
|
self::$getorderdetail = 'http://openapi.uupaotui.com/v2_0/getorderdetail.ashx';
|
|
}
|
|
//获取验证码
|
|
public function getcode($data,$appkey)
|
|
{
|
|
$path = self::$getcode;
|
|
$content = $this->binding($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//获取openid
|
|
public function getopenid($data,$appkey)
|
|
{
|
|
$path = self::$getopenid;
|
|
$content = $this->binding($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//绑定商家公用请求方法
|
|
public function binding($data,$appkey,$path)
|
|
{
|
|
header("Content-type: text/html; charset=utf-8");
|
|
$data['timestamp'] = time();
|
|
$data['nonce_str'] = $this->randomkeys(32);
|
|
$data['sign'] = $this->sign($data,$appkey);
|
|
$content = $this->request_post($path,$data);
|
|
return $content;
|
|
}
|
|
//获取余额详情
|
|
public function getbalance($data,$appkey)
|
|
{
|
|
$path = self::$balance;
|
|
$content = $this->uu_request($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//充值
|
|
public function recharge($data,$appkey)
|
|
{
|
|
$path = self::$recharge;
|
|
$content = $this->uu_request($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//订单价格
|
|
public function getorderprice($data,$appkey)
|
|
{
|
|
$path = self::$getorderprice;
|
|
$content = $this->uu_request($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//下单
|
|
public function addorder($data,$appkey)
|
|
{
|
|
$path = self::$addorder;
|
|
$content = $this->uu_request($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//取消订单
|
|
public function cancelorder($data,$appkey)
|
|
{
|
|
$path = self::$cancelorder;
|
|
$content = $this->uu_request($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//订单详情
|
|
public function getorderdetail($data,$appkey)
|
|
{
|
|
$path = self::$getorderdetail;
|
|
$content = $this->uu_request($data,$appkey,$path);
|
|
return $content;
|
|
}
|
|
//获取已开通的城市列表
|
|
public function getcitylist()
|
|
{
|
|
$content = $this->uu_request();
|
|
}
|
|
//公共请求方法
|
|
private function uu_request($data,$appkey,$path)
|
|
{
|
|
header("Content-type: text/html; charset=utf-8");
|
|
$data['nonce_str'] = $this->randomkeys(32);
|
|
$data['timestamp'] = time();
|
|
$data['sign'] = $this->sign($data,$appkey);
|
|
$content = $this->request_post($path,$data);
|
|
return $content;
|
|
}
|
|
private function request_post($url = '', $post_data = array()) {
|
|
if (empty($url) || empty($post_data)) {
|
|
return false;
|
|
}
|
|
$arr = [];
|
|
foreach ($post_data as $key => $value) {
|
|
$arr[] = $key.'='.$value;
|
|
}
|
|
$curlPost = implode('&', $arr);
|
|
$postUrl = $url;
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL,$postUrl);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
|
$data = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $data;
|
|
}
|
|
|
|
// 生成随机字符串
|
|
private function randomkeys($length)
|
|
{
|
|
$pattern = '1234567890abcdefghijklmnopqrstuvwxyz
|
|
ABCDEFGHIJKLOMNOPQRSTUVWXYZ,./&l
|
|
t;>?;#:@~[]{}-_=+)(*&^%$?!'; //字符池
|
|
$key = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$key .= $pattern{mt_rand(0, 35)}; //生成php随机数
|
|
}
|
|
return $key;
|
|
}
|
|
|
|
// 生成签名
|
|
private function sign($data, $appkey) {
|
|
ksort($data);
|
|
$arr = '';
|
|
foreach ($data as $key => $value) {
|
|
$arr .= $key.'='.$value.'&';
|
|
}
|
|
$arr .= 'key='.$appkey;
|
|
$str = strtoupper($arr);
|
|
return strtoupper(md5($str));
|
|
}
|
|
} |