add clear
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/4/19 0019
|
||||
* Time: 16:12
|
||||
*/
|
||||
|
||||
namespace qq;
|
||||
|
||||
use common\Decode;
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
|
||||
class Account extends SmallProgram
|
||||
{
|
||||
/**
|
||||
* @param $code
|
||||
* @return Result
|
||||
*/
|
||||
public function login($code)
|
||||
{
|
||||
$param['appid'] = $this->config->getAppid();
|
||||
$param['secret'] = $this->config->getAppsecret();
|
||||
$param['js_code'] = $code;
|
||||
$param['grant_type'] = 'authorization_code';
|
||||
|
||||
if (empty($code)) {
|
||||
return new Result(['code' => 404, 'message' => '临时登录凭证不能为空.']);
|
||||
}
|
||||
|
||||
$this->request->setHost('api.q.qq.com');
|
||||
$this->request->setMethod(HttpClient::GET);
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->setUseSwoole($this->config->isUsrSwoole());
|
||||
|
||||
return $this->request->get('sns/jscode2session', $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $encryptedData
|
||||
* @param $iv
|
||||
* @param $sessionKey
|
||||
* @param $asArray
|
||||
* @return object|array
|
||||
* @throws
|
||||
*
|
||||
* * <li>-41001: encodingAesKey 非法</li>
|
||||
* <li>-41003: aes 解密失败</li>
|
||||
* <li>-41004: 解密后得到的buffer非法</li>
|
||||
* <li>-41005: base64加密失败</li>
|
||||
* <li>-41016: base64解密失败</li>
|
||||
*/
|
||||
public function decode($encryptedData, $iv, $sessionKey, $asArray = false)
|
||||
{
|
||||
$decode = new Decode();
|
||||
$decode->setAppId($this->config->getAppid());
|
||||
$decode->setIv($iv);
|
||||
$decode->setEncryptedData($encryptedData);
|
||||
$decode->setSessionKey($sessionKey);
|
||||
return $decode->decode($asArray);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
class GamePrePay extends SmallProgram
|
||||
{
|
||||
|
||||
private $url = 'https://api.q.qq.com/api/json/openApiPay/GamePrePay?access_token=';
|
||||
|
||||
|
||||
}
|
||||
-599
@@ -1,599 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
use common\Help;
|
||||
|
||||
class Notify extends SmallProgram
|
||||
{
|
||||
public $appid = '';
|
||||
public $mch_id = '';
|
||||
public $device_info = '';
|
||||
public $nonce_str = '';
|
||||
public $sign = '';
|
||||
public $sign_type = '';
|
||||
public $result_code = '';
|
||||
public $err_code = '';
|
||||
public $err_code_des = '';
|
||||
public $openid = '';
|
||||
public $is_subscribe = '';
|
||||
public $trade_type = '';
|
||||
public $bank_type = '';
|
||||
public $total_fee = '';
|
||||
public $settlement_total_fee = '';
|
||||
public $fee_type = '';
|
||||
public $cash_fee = '';
|
||||
public $cash_fee_type = '';
|
||||
public $coupon_fee = '';
|
||||
public $coupon_count = '';
|
||||
public $coupon_type_n = '';
|
||||
public $coupon_id_n = '';
|
||||
public $coupon_fee_n = '';
|
||||
public $transaction_id = '';
|
||||
public $out_trade_no = '';
|
||||
public $attach = '';
|
||||
public $time_end = '';
|
||||
public $return_code = '';
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* 判断是否完成支付
|
||||
*/
|
||||
public function isSuccess()
|
||||
{
|
||||
if ($this->getReturnCode() != "SUCCESS") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getResultCode() != 'SUCCESS') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return $this
|
||||
*/
|
||||
public function setPayNotifyData(array $params)
|
||||
{
|
||||
if (!$this->validation($params)) {
|
||||
$this->setResultCode('FAIL');
|
||||
$this->setErrCodeDes('签名错误');
|
||||
unset($params['result_code'], $params['err_code_des']);
|
||||
}
|
||||
foreach ($params as $key => $val) {
|
||||
if (!property_exists($this, $key)) {
|
||||
continue;
|
||||
}
|
||||
$this->$key = $val;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
public function validation(array $params)
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
|
||||
$signType = $this->config->getSignType();
|
||||
$privateKey = $this->config->getKey();
|
||||
$nowSign = Help::sign($params, $privateKey, $signType);
|
||||
if ($sign === $nowSign) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAppid()
|
||||
{
|
||||
return $this->appid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $appid
|
||||
* @return Notify
|
||||
*/
|
||||
public function setAppid($appid)
|
||||
{
|
||||
$this->appid = $appid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMchId()
|
||||
{
|
||||
return $this->mch_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mch_id
|
||||
* @return Notify
|
||||
*/
|
||||
public function setMchId($mch_id)
|
||||
{
|
||||
$this->mch_id = $mch_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDeviceInfo()
|
||||
{
|
||||
return $this->device_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $device_info
|
||||
* @return Notify
|
||||
*/
|
||||
public function setDeviceInfo($device_info)
|
||||
{
|
||||
$this->device_info = $device_info;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNonceStr()
|
||||
{
|
||||
return $this->nonce_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $nonce_str
|
||||
* @return Notify
|
||||
*/
|
||||
public function setNonceStr($nonce_str)
|
||||
{
|
||||
$this->nonce_str = $nonce_str;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSign()
|
||||
{
|
||||
return $this->sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sign
|
||||
* @return Notify
|
||||
*/
|
||||
public function setSign($sign)
|
||||
{
|
||||
$this->sign = $sign;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSignType()
|
||||
{
|
||||
return $this->sign_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sign_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setSignType($sign_type)
|
||||
{
|
||||
$this->sign_type = $sign_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResultCode()
|
||||
{
|
||||
return $this->result_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $result_code
|
||||
* @return Notify
|
||||
*/
|
||||
public function setResultCode($result_code)
|
||||
{
|
||||
$this->result_code = $result_code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getErrCode()
|
||||
{
|
||||
return $this->err_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $err_code
|
||||
* @return Notify
|
||||
*/
|
||||
public function setErrCode($err_code)
|
||||
{
|
||||
$this->err_code = $err_code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getErrCodeDes()
|
||||
{
|
||||
return $this->err_code_des;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $err_code_des
|
||||
* @return Notify
|
||||
*/
|
||||
public function setErrCodeDes($err_code_des)
|
||||
{
|
||||
$this->err_code_des = $err_code_des;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOpenid()
|
||||
{
|
||||
return $this->openid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $openid
|
||||
* @return Notify
|
||||
*/
|
||||
public function setOpenid($openid)
|
||||
{
|
||||
$this->openid = $openid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIsSubscribe()
|
||||
{
|
||||
return $this->is_subscribe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $is_subscribe
|
||||
* @return Notify
|
||||
*/
|
||||
public function setIsSubscribe($is_subscribe)
|
||||
{
|
||||
$this->is_subscribe = $is_subscribe;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTradeType()
|
||||
{
|
||||
return $this->trade_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $trade_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTradeType($trade_type)
|
||||
{
|
||||
$this->trade_type = $trade_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBankType()
|
||||
{
|
||||
return $this->bank_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $bank_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setBankType($bank_type)
|
||||
{
|
||||
$this->bank_type = $bank_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTotalFee()
|
||||
{
|
||||
return $this->total_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $total_fee
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTotalFee($total_fee)
|
||||
{
|
||||
$this->total_fee = $total_fee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSettlementTotalFee()
|
||||
{
|
||||
return $this->settlement_total_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $settlement_total_fee
|
||||
* @return Notify
|
||||
*/
|
||||
public function setSettlementTotalFee($settlement_total_fee)
|
||||
{
|
||||
$this->settlement_total_fee = $settlement_total_fee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFeeType()
|
||||
{
|
||||
return $this->fee_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $fee_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setFeeType($fee_type)
|
||||
{
|
||||
$this->fee_type = $fee_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashFee()
|
||||
{
|
||||
return $this->cash_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $cash_fee
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCashFee($cash_fee)
|
||||
{
|
||||
$this->cash_fee = $cash_fee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashFeeType()
|
||||
{
|
||||
return $this->cash_fee_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $cash_fee_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCashFeeType($cash_fee_type)
|
||||
{
|
||||
$this->cash_fee_type = $cash_fee_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCouponFee()
|
||||
{
|
||||
return $this->coupon_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $coupon_fee
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCouponFee($coupon_fee)
|
||||
{
|
||||
$this->coupon_fee = $coupon_fee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCouponCount()
|
||||
{
|
||||
return $this->coupon_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $coupon_count
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCouponCount($coupon_count)
|
||||
{
|
||||
$this->coupon_count = $coupon_count;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCouponTypeN()
|
||||
{
|
||||
return $this->coupon_type_n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $coupon_type_n
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCouponTypeN($coupon_type_n)
|
||||
{
|
||||
$this->coupon_type_n = $coupon_type_n;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCouponIdN()
|
||||
{
|
||||
return $this->coupon_id_n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $coupon_id_n
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCouponIdN($coupon_id_n)
|
||||
{
|
||||
$this->coupon_id_n = $coupon_id_n;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCouponFeeN()
|
||||
{
|
||||
return $this->coupon_fee_n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $coupon_fee_n
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCouponFeeN($coupon_fee_n)
|
||||
{
|
||||
$this->coupon_fee_n = $coupon_fee_n;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTransactionId()
|
||||
{
|
||||
return $this->transaction_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $transaction_id
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTransactionId($transaction_id)
|
||||
{
|
||||
$this->transaction_id = $transaction_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOutTradeNo()
|
||||
{
|
||||
return $this->out_trade_no;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $out_trade_no
|
||||
* @return Notify
|
||||
*/
|
||||
public function setOutTradeNo($out_trade_no)
|
||||
{
|
||||
$this->out_trade_no = $out_trade_no;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAttach()
|
||||
{
|
||||
return $this->attach;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attach
|
||||
* @return Notify
|
||||
*/
|
||||
public function setAttach($attach)
|
||||
{
|
||||
$this->attach = $attach;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTimeEnd()
|
||||
{
|
||||
return $this->time_end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $time_end
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTimeEnd($time_end)
|
||||
{
|
||||
$this->time_end = $time_end;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReturnCode()
|
||||
{
|
||||
return $this->return_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $return_code
|
||||
* @return Notify
|
||||
*/
|
||||
public function setReturnCode($return_code)
|
||||
{
|
||||
$this->return_code = $return_code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
|
||||
class QrCode extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
private $wxaqr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
||||
private $getwxacode = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=';
|
||||
private $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
||||
|
||||
private $savePath = __DIR__ . '/../../../';
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*/
|
||||
public function setSavePath($path)
|
||||
{
|
||||
$this->savePath = $path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createwxaqrcode($path, $width)
|
||||
{
|
||||
$url = $this->wxaqr . $this->getAccessToken();
|
||||
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getwxacode($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '')
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
|
||||
$url = $this->getwxacode . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getwxacodeunlimit($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '')
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
|
||||
$url = $this->getwxacodeunlimit . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $body
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function saveByPath($body)
|
||||
{
|
||||
if (!is_null($json = json_decode($body))) {
|
||||
throw new \Exception($json['errmsg'], $json['errcode']);
|
||||
}
|
||||
|
||||
$push = md5_file($body) . '.png';
|
||||
file_put_contents($this->savePath . $push, $this->savePath);
|
||||
return $this->savePath . $push;
|
||||
}
|
||||
}
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/3/26 0026
|
||||
* Time: 10:22
|
||||
*/
|
||||
|
||||
namespace qq;
|
||||
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
use common\Help;
|
||||
|
||||
class Recharge extends SmallProgram
|
||||
{
|
||||
private $money = 0;
|
||||
|
||||
private $orderNo;
|
||||
|
||||
private $data = [];
|
||||
|
||||
private $transfers = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
||||
private $unifiedorder = 'https://qpay.qq.com/cgi-bin/pay/qpay_unified_order.cgi';
|
||||
|
||||
/**
|
||||
* @param int $money
|
||||
* @param string $orderNo
|
||||
* @param string $openId
|
||||
* @return array|mixed|Result
|
||||
* @throws
|
||||
*/
|
||||
public function recharge(int $money, string $orderNo, $openId = '')
|
||||
{
|
||||
if ($money < 0) {
|
||||
return new Result(['code' => 500, 'message' => '充值金额不能小于0.']);
|
||||
}
|
||||
$this->money = $money;
|
||||
$this->orderNo = $orderNo;
|
||||
$this->data['openid'] = $openId;
|
||||
|
||||
$config = $this->config;
|
||||
$this->request->setCallback(function ($result, $body) use ($config) {
|
||||
$data = Help::toArray($result);
|
||||
if (isset($data['sign'])) {
|
||||
$sign = $data['sign'];
|
||||
unset($data['sign']);
|
||||
}
|
||||
|
||||
$return = [];
|
||||
// $_sign = Help::sign($data, $config->getKey(), $config->getSignType());
|
||||
if (!isset($sign)) {
|
||||
$return['code'] = -1;
|
||||
$return['message'] = '返回数据签名验证失败';
|
||||
// } else if ($sign != $_sign) {
|
||||
// $return['code'] = 401;
|
||||
// $return['message'] = '预支付系统数据签名验证失败!';
|
||||
} else {
|
||||
$return['code'] = 0;
|
||||
$return['data'] = $data;
|
||||
$return['data']['postBody'] = $body;
|
||||
if ($data['return_code'] == 'FAIL') {
|
||||
$return['code'] = -1;
|
||||
$return['message'] = $data['return_msg'];
|
||||
}
|
||||
}
|
||||
return new Result($return);
|
||||
});
|
||||
return $this->send($this->unifiedorder, $this->builder());
|
||||
}
|
||||
|
||||
/**
|
||||
* 'appId' => $result['appid'],
|
||||
* 'nonceStr' => $result['nonce_str'],
|
||||
* 'package' => 'prepay_id=' . $result['prepay_id'],
|
||||
* 'signType' => 'MD5',
|
||||
* 'timeStamp' => (string)time(),
|
||||
* @param $prepay_id
|
||||
* @return array
|
||||
*/
|
||||
public function reception($prepay_id)
|
||||
{
|
||||
$array = [
|
||||
'appId' => $this->config->getAppid(),
|
||||
'nonceStr' => Help::random(32),
|
||||
'package' => 'prepay_id=' . $prepay_id,
|
||||
'signType' => 'MD5',
|
||||
'timeStamp' => (string)time(),
|
||||
];
|
||||
$key = $this->config->getKey();
|
||||
$sign_type = $this->config->getSignType();
|
||||
$array['paySign'] = Help::sign($array, $key, $sign_type);
|
||||
$array['appId'] = $this->config->getAppid();
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function builder()
|
||||
{
|
||||
$data = [
|
||||
'appid' => $this->config->getAppid(),
|
||||
'mch_id' => $this->config->getMchId(),
|
||||
'nonce_str' => Help::random(32),
|
||||
'body' => $this->config->getBody(),
|
||||
'out_trade_no' => $this->orderNo,
|
||||
'total_fee' => $this->money,
|
||||
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],
|
||||
'notify_url' => $this->config->getNotifyUrl(),
|
||||
'trade_type' => $this->config->getTradeType(),
|
||||
];
|
||||
|
||||
$this->data = array_merge($data, $this->data);
|
||||
|
||||
$key = $this->config->getKey();
|
||||
$sign_type = $this->config->getSignType();
|
||||
|
||||
$this->data['sign_type'] = $this->config->getSignType();
|
||||
$this->data['sign'] = Help::sign($this->data, $key, $sign_type);
|
||||
|
||||
return Help::toXml($this->data);
|
||||
}
|
||||
|
||||
public function getSignData()
|
||||
{
|
||||
$data = $this->data;
|
||||
$data['key'] = $this->config->getKey();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $money
|
||||
* @param $openid
|
||||
* @param $order
|
||||
* @param $desc
|
||||
* @return Result
|
||||
* @throws
|
||||
*
|
||||
* 提现
|
||||
*/
|
||||
public function cashWithdrawal($money, $openid, $order, $desc = '零钱提现')
|
||||
{
|
||||
$array = [
|
||||
'nonce_str' => Help::random(32),
|
||||
'partner_trade_no' => $order,
|
||||
'mchid' => $this->config->getMchId(),
|
||||
'mch_appid' => $this->config->getAppid(),
|
||||
'openid' => $openid,
|
||||
'check_name' => 'NO_CHECK',
|
||||
'amount' => $money * 100,
|
||||
'spbill_create_ip' => $this->config->getRemoteAddr(),
|
||||
'desc' => $desc,
|
||||
];
|
||||
|
||||
$key = $this->config->getKey();
|
||||
$sign_type = $this->config->getSignType();
|
||||
$array['sign'] = Help::sign($array, $key, $sign_type);
|
||||
|
||||
$this->request->setCallback(function ($data) {
|
||||
$array = Help::toArray($data);
|
||||
if ($array['result_code'] != 'SUCCESS') {
|
||||
$data = ['code' => $array['err_code'], 'message' => $array['err_code_des']];
|
||||
} else {
|
||||
$data = ['code' => 0, 'message' => '支付成功'];
|
||||
}
|
||||
return new Result($data);
|
||||
});
|
||||
return $this->send($this->transfers, Help::toXml($array));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function send($url, $data)
|
||||
{
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->addHeader('Content-Type', 'text/xml');
|
||||
return $this->request->send($url, $data);
|
||||
}
|
||||
}
|
||||
-500
@@ -1,500 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
use common\Help;
|
||||
use common\Result;
|
||||
use qq\result\RedHatResult;
|
||||
|
||||
class Redhat extends SmallProgram
|
||||
{
|
||||
|
||||
private $charset = 'UTF8';
|
||||
private $nonce_str = '';
|
||||
private $sign = '';
|
||||
private $mch_billno = '';
|
||||
private $mch_id = '';
|
||||
private $mch_name = '';
|
||||
private $qqappid = '';
|
||||
private $re_openid = '';
|
||||
private $total_amount = '';
|
||||
private $total_num = '';
|
||||
private $wishing = '';
|
||||
private $act_name = '';
|
||||
private $icon_id = '';
|
||||
private $banner_id = '';
|
||||
private $notify_url = '';
|
||||
private $not_send_msg = '';
|
||||
private $min_value = '';
|
||||
private $max_value = '';
|
||||
private $key = '';
|
||||
private $signType = '';
|
||||
|
||||
|
||||
private $sendUrl = 'https://api.qpay.qq.com/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
|
||||
private $searchUrl = 'https://qpay.qq.com/cgi-bin/mch_query/qpay_hb_mch_list_query.cgi';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setKey(string $key): Redhat
|
||||
{
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSignType(): string
|
||||
{
|
||||
return $this->signType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $signType
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setSignType(string $signType): Redhat
|
||||
{
|
||||
$this->signType = $signType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCharset(): string
|
||||
{
|
||||
return $this->charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $charset
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setCharset(string $charset): Redhat
|
||||
{
|
||||
$this->charset = $charset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceStr(): string
|
||||
{
|
||||
return $this->nonce_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $nonce_str
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setNonceStr(string $nonce_str): Redhat
|
||||
{
|
||||
$this->nonce_str = $nonce_str;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSign(): string
|
||||
{
|
||||
return $this->sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sign
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setSign(string $sign): Redhat
|
||||
{
|
||||
$this->sign = $sign;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMchBillno(): string
|
||||
{
|
||||
if (empty($this->mch_billno)) {
|
||||
return '1559179381' . date('Ymd') . mt_rand(11, 99) . date('His') . mt_rand(11, 99);
|
||||
}
|
||||
return $this->mch_billno;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mch_billno
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setMchBillno(string $mch_billno): Redhat
|
||||
{
|
||||
$this->mch_billno = $mch_billno;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMchId(): string
|
||||
{
|
||||
return $this->mch_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mch_id
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setMchId(string $mch_id): Redhat
|
||||
{
|
||||
$this->mch_id = $mch_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMchName(): string
|
||||
{
|
||||
return $this->mch_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mch_name
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setMchName(string $mch_name): Redhat
|
||||
{
|
||||
$this->mch_name = $mch_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQqappid(): string
|
||||
{
|
||||
return $this->qqappid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $qqappid
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setQqappid(string $qqappid): Redhat
|
||||
{
|
||||
$this->qqappid = $qqappid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReOpenid(): string
|
||||
{
|
||||
return $this->re_openid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $re_openid
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setReOpenid(string $re_openid): Redhat
|
||||
{
|
||||
$this->re_openid = $re_openid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTotalAmount(): string
|
||||
{
|
||||
return $this->total_amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $total_amount
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setTotalAmount(string $total_amount): Redhat
|
||||
{
|
||||
$this->total_amount = $total_amount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTotalNum(): string
|
||||
{
|
||||
return $this->total_num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $total_num
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setTotalNum(string $total_num): Redhat
|
||||
{
|
||||
$this->total_num = $total_num;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWishing(): string
|
||||
{
|
||||
return $this->wishing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $wishing
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setWishing(string $wishing): Redhat
|
||||
{
|
||||
$this->wishing = $wishing;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getActName(): string
|
||||
{
|
||||
return $this->act_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $act_name
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setActName(string $act_name): Redhat
|
||||
{
|
||||
$this->act_name = $act_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIconId(): string
|
||||
{
|
||||
return $this->icon_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icon_id
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setIconId(string $icon_id): Redhat
|
||||
{
|
||||
$this->icon_id = $icon_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBannerId(): string
|
||||
{
|
||||
return $this->banner_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $banner_id
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setBannerId(string $banner_id): Redhat
|
||||
{
|
||||
$this->banner_id = $banner_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNotifyUrl(): string
|
||||
{
|
||||
return $this->notify_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $notify_url
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setNotifyUrl(string $notify_url): Redhat
|
||||
{
|
||||
$this->notify_url = $notify_url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNotSendMsg(): string
|
||||
{
|
||||
return $this->not_send_msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $not_send_msg
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setNotSendMsg(string $not_send_msg): Redhat
|
||||
{
|
||||
$this->not_send_msg = $not_send_msg;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMinValue(): string
|
||||
{
|
||||
return $this->min_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $min_value
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setMinValue(string $min_value): Redhat
|
||||
{
|
||||
$this->min_value = $min_value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMaxValue(): string
|
||||
{
|
||||
return $this->max_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $max_value
|
||||
* @return Redhat
|
||||
*/
|
||||
public function setMaxValue(string $max_value): Redhat
|
||||
{
|
||||
$this->max_value = $max_value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* 构建请求参数
|
||||
*/
|
||||
private function generate()
|
||||
{
|
||||
$requestParam['charset'] = $this->getCharset();
|
||||
$requestParam['nonce_str'] = $this->getNonceStr();
|
||||
$requestParam['mch_billno'] = $this->getMchBillno();
|
||||
$requestParam['mch_id'] = $this->getMchId();
|
||||
$requestParam['mch_name'] = $this->getMchName();
|
||||
$requestParam['qqappid'] = $this->getQqappid();
|
||||
$requestParam['re_openid'] = $this->getReOpenid();
|
||||
$requestParam['total_amount'] = $this->getTotalAmount() * 100;
|
||||
$requestParam['min_value'] = $this->getMinValue() * 100;
|
||||
$requestParam['max_value'] = $this->getMaxValue() * 100;
|
||||
$requestParam['total_num'] = $this->getTotalNum();
|
||||
$requestParam['wishing'] = $this->getWishing();
|
||||
$requestParam['act_name'] = $this->getActName();
|
||||
$requestParam['icon_id'] = $this->getIconId();
|
||||
$requestParam['notify_url'] = $this->getNotifyUrl();
|
||||
|
||||
$requestParam['sign'] = $this->builderSign($requestParam);
|
||||
|
||||
return $requestParam;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $requestParam
|
||||
* @return string
|
||||
*/
|
||||
private function builderSign($requestParam)
|
||||
{
|
||||
return Help::sign($requestParam, $this->getKey(), $this->getSignType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws
|
||||
* 发红包
|
||||
*/
|
||||
public function redEnvelopes()
|
||||
{
|
||||
$callback = function ($response) {
|
||||
$json = json_decode($response, true);
|
||||
if (isset($json['return_code']) && $json['return_code'] != 'SUCCESS') {
|
||||
$message = $json['return_msg'] ?? $json['retmsg'];
|
||||
$param = ['code' => 500, 'message' => $message];
|
||||
} else if ($json['retcode'] != 0) {
|
||||
$param = ['code' => $json['retcode'], 'message' => $json['retmsg']];
|
||||
} else {
|
||||
$param = ['code' => 0, 'message' => $json['retmsg'], 'data' => ['listid' => $json['listid']]];
|
||||
}
|
||||
return new Result($param);
|
||||
};
|
||||
$this->request->setCallback($callback);
|
||||
$response = $this->request->post($this->sendUrl, $this->generate());
|
||||
if (!$response->isResultsOK()) {
|
||||
throw new \Exception($response->getMessage());
|
||||
}
|
||||
return $response->getData('listid');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $listid
|
||||
* @param null $orderNo
|
||||
* @return RedHatResult
|
||||
* @throws \Exception
|
||||
*
|
||||
* 查询红包状态
|
||||
*/
|
||||
public function searchByOrderNo($listid, $orderNo = null)
|
||||
{
|
||||
$requestParam['nonce_str'] = $this->getNonceStr();
|
||||
$requestParam['mch_id'] = $this->getMchId();
|
||||
$requestParam['listid'] = $listid;
|
||||
if (!empty($orderNo)) {
|
||||
$requestParam['mch_billno'] = $orderNo;
|
||||
}
|
||||
$requestParam['sign'] = $this->builderSign($requestParam);
|
||||
$this->request->setCallback(function ($response) {
|
||||
$response = json_decode($response, true);
|
||||
if (!isset($response['result']) || $response['result'] != 0) {
|
||||
$param = ['code' => 500, 'message' => $response['res_info'] ?? '订单查询失败!', 'data' => $response];
|
||||
} else {
|
||||
$param = ['code' => 0, 'message' => 'system success!', 'data' => $response];
|
||||
}
|
||||
return new Result($param);
|
||||
});
|
||||
$response = $this->request->get($this->searchUrl, $requestParam);
|
||||
if (!$response->isResultsOK()) {
|
||||
throw new \Exception($response->getMessage());
|
||||
}
|
||||
return new RedHatResult($response->getData());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\Result;
|
||||
|
||||
/**
|
||||
* Class SecCheck
|
||||
* @package qq
|
||||
*/
|
||||
class SecCheck extends SmallProgram
|
||||
{
|
||||
|
||||
private $_url = 'https://api.q.qq.com/api/json/security/ImgSecCheck?access_token=';
|
||||
|
||||
private $_msgUrl = 'https://api.q.qq.com/api/json/security/MsgSecCheck?access_token=';
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return array|Result|mixed
|
||||
*/
|
||||
public function image($path = '')
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
return $this->sendError('文件不存在', 404);
|
||||
}
|
||||
$this->request->setUseSwoole(false);
|
||||
$this->request->setHeader(['Content-Type' => 'multipart/form-data']);
|
||||
return $this->request->post($this->_url . $this->config->getAccessToken(), ['media' => new \CURLFile($path)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $content
|
||||
* @return array|Result|mixed
|
||||
*/
|
||||
public function text($content)
|
||||
{
|
||||
if (empty($content)) {
|
||||
return $this->sendError('文件不存在', 404);
|
||||
}
|
||||
$this->request->setUseSwoole(false);
|
||||
$this->request->setHeader(['Content-Type' => 'application/json']);
|
||||
return $this->request->post($this->_msgUrl . $this->config->getAccessToken(), ['content' => $content]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\Miniprogarampage;
|
||||
|
||||
class SmallProgram extends Miniprogarampage
|
||||
{
|
||||
|
||||
protected static $instance;
|
||||
|
||||
private $url = 'https://api.q.qq.com/api/getToken';
|
||||
|
||||
|
||||
/**
|
||||
* @param $get_token
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function generateAccess_token($get_token = false)
|
||||
{
|
||||
if (!empty($this->config->getToken())) {
|
||||
return $this->config->getToken();
|
||||
}
|
||||
$query = [
|
||||
'grant_type' => 'client_credential',
|
||||
'appid' => $this->config->getAppid(),
|
||||
'secret' => $this->config->getAppsecret()
|
||||
];
|
||||
$param = $this->request->get($this->url, $query);
|
||||
if (!$param->isResultsOK()) {
|
||||
return null;
|
||||
}
|
||||
if ($get_token) {
|
||||
return $param->getData('access_token');
|
||||
}
|
||||
return $param->getData();
|
||||
}
|
||||
}
|
||||
-136
@@ -1,136 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\Result;
|
||||
|
||||
class Subject extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
private $keywords = [];
|
||||
private $templateId = '';
|
||||
private $openId = '';
|
||||
private $defaultUrl = '';
|
||||
private $page = 'pages/index/index';
|
||||
private $emphasis_keyword = '';
|
||||
|
||||
private $sendUrl = 'https://api.q.qq.com/api/json/subscribe/SendSubscriptionMessage';
|
||||
|
||||
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateId
|
||||
*/
|
||||
public function setTemplateId(string $templateId)
|
||||
{
|
||||
$this->templateId = $templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $openId
|
||||
*/
|
||||
public function setOpenId(string $openId)
|
||||
{
|
||||
$this->openId = $openId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $defaultUrl
|
||||
*/
|
||||
public function setDefaultUrl(string $defaultUrl)
|
||||
{
|
||||
$this->defaultUrl = $defaultUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $page
|
||||
*/
|
||||
public function setPage(string $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emphasis_keyword
|
||||
*/
|
||||
public function setEmphasisKeyword(string $emphasis_keyword)
|
||||
{
|
||||
$this->emphasis_keyword = $emphasis_keyword;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $index
|
||||
* @param $context
|
||||
* @param $color
|
||||
*/
|
||||
public function replaceKeyword($index, $context, $color = '')
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . $index] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $color
|
||||
* @param $context
|
||||
*/
|
||||
public function addKeyword($context, $color = null)
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . (count($this->keywords) + 1)] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*
|
||||
* 奴隶交易通知
|
||||
*/
|
||||
public function sendTemplate()
|
||||
{
|
||||
$url = $this->sendUrl . '?access_token=' . $this->config->getAccessToken();
|
||||
$params = json_encode([
|
||||
"touser" => $this->openId,
|
||||
"template_id" => $this->templateId,
|
||||
"page" => $this->page,
|
||||
"data" => $this->keywords,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
if (!empty($this->emphasis_keyword)) {
|
||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
||||
}
|
||||
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->addHeader('content-type', 'application/json');
|
||||
|
||||
$result = $this->request->post($url, $params);
|
||||
$result->append('postBody', $params);
|
||||
|
||||
$this->openId = '';
|
||||
$this->keywords = [];
|
||||
$this->templateId = '';
|
||||
$this->page = '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
-152
@@ -1,152 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/4/8 0008
|
||||
* Time: 9:49
|
||||
*/
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\Result;
|
||||
|
||||
class Template extends SmallProgram
|
||||
{
|
||||
|
||||
private $keywords = [];
|
||||
private $templateId = '';
|
||||
private $formId = '';
|
||||
private $openId = '';
|
||||
private $defaultUrl = '';
|
||||
private $page = 'pages/index/index';
|
||||
private $emphasis_keyword = '';
|
||||
|
||||
private $sendUrl = 'https://api.q.qq.com/api/json/template/send';
|
||||
|
||||
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateId
|
||||
*/
|
||||
public function setTemplateId(string $templateId)
|
||||
{
|
||||
$this->templateId = $templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formId
|
||||
*/
|
||||
public function setFormId(string $formId)
|
||||
{
|
||||
$this->formId = $formId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $openId
|
||||
*/
|
||||
public function setOpenId(string $openId)
|
||||
{
|
||||
$this->openId = $openId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $defaultUrl
|
||||
*/
|
||||
public function setDefaultUrl(string $defaultUrl)
|
||||
{
|
||||
$this->defaultUrl = $defaultUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $page
|
||||
*/
|
||||
public function setPage(string $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emphasis_keyword
|
||||
*/
|
||||
public function setEmphasisKeyword(string $emphasis_keyword)
|
||||
{
|
||||
$this->emphasis_keyword = $emphasis_keyword;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $index
|
||||
* @param $context
|
||||
* @param $color
|
||||
*/
|
||||
public function replaceKeyword($index, $context, $color = '')
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . $index] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $color
|
||||
* @param $context
|
||||
*/
|
||||
public function addKeyword($context, $color = null)
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . (count($this->keywords) + 1)] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*
|
||||
* 奴隶交易通知
|
||||
*/
|
||||
public function sendTemplate()
|
||||
{
|
||||
$url = $this->sendUrl . '?access_token=' . $this->config->getAccessToken();
|
||||
|
||||
$params = [
|
||||
"touser" => $this->openId,
|
||||
"template_id" => $this->templateId,
|
||||
"page" => $this->page,
|
||||
"form_id" => $this->formId,
|
||||
"data" => $this->keywords,
|
||||
];
|
||||
|
||||
if (!empty($this->emphasis_keyword)) {
|
||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
||||
}
|
||||
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->addHeader('content-type', 'application/json');
|
||||
|
||||
$result = $this->request->post($url, $params);
|
||||
$result->append('postBody', $params);
|
||||
|
||||
$this->openId = '';
|
||||
$this->keywords = [];
|
||||
$this->formId = '';
|
||||
$this->templateId = '';
|
||||
$this->page = '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
|
||||
class Token extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq\result;
|
||||
|
||||
/**
|
||||
* Class RedHatResult
|
||||
* @package qq\result
|
||||
*/
|
||||
class RedHatResult
|
||||
{
|
||||
|
||||
public $result;
|
||||
public $res_info;
|
||||
|
||||
public $listid;
|
||||
public $state;
|
||||
public $total_num;
|
||||
public $recv_num;
|
||||
public $total_amount;
|
||||
public $recv_amount;
|
||||
public $recv_details;
|
||||
public $uin;
|
||||
|
||||
|
||||
const RED_HAT_STATUS_PAID = 1;
|
||||
const RED_HAT_STATUS_SNATCHED = 2;
|
||||
const RED_HAT_STATUS_EXPIRED = 3;
|
||||
const RED_HAT_STATUS_REFUNDED = 4;
|
||||
|
||||
|
||||
/**
|
||||
* RedHatResult constructor.
|
||||
* @param array $array
|
||||
*/
|
||||
public function __construct(array $array)
|
||||
{
|
||||
$this->init($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
* @return $this
|
||||
*/
|
||||
private function init($array)
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if (!property_exists($this, $key)) {
|
||||
continue;
|
||||
}
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($field)
|
||||
{
|
||||
return $this->$field;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* 是否已完成支付
|
||||
*/
|
||||
public function isPaid()
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_PAID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* 是否已抢完
|
||||
*/
|
||||
public function isSnatched()
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_SNATCHED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired()
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_EXPIRED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isRefunded()
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_REFUNDED;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user