Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7953bc801 | |||
| 26e691fec8 | |||
| 00f046fba1 | |||
| ad78b85ea0 | |||
| a4e504e5e3 | |||
| 706088998b | |||
| cf52645c42 | |||
| 8e27dc41e5 | |||
| 5202270073 | |||
| 93e763c880 | |||
| 6136633a83 | |||
| fa67c60088 | |||
| fecac0e850 | |||
| 1b89cd61ae | |||
| a1c85376e1 | |||
| c323b97112 | |||
| 663bf23ebd | |||
| d769ba0aaa | |||
| e44b1c0989 | |||
| b24d18dc55 | |||
| cc87f8b440 | |||
| 4de90eff88 |
@@ -12,6 +12,7 @@ class Account extends Miniprogarampage
|
|||||||
|
|
||||||
private $wxaqr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
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 $getwxacode = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=';
|
||||||
|
private $publicInfo = 'https://api.weixin.qq.com/cgi-bin/user/info?';
|
||||||
private $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
private $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
||||||
|
|
||||||
private $savePath = __DIR__ . '/../../../';
|
private $savePath = __DIR__ . '/../../../';
|
||||||
@@ -48,6 +49,24 @@ class Account extends Miniprogarampage
|
|||||||
return $this->request->get('/sns/jscode2session', $param);
|
return $this->request->get('/sns/jscode2session', $param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $openid
|
||||||
|
* @return array|mixed|Result
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function getPublicUserInfo($openid)
|
||||||
|
{
|
||||||
|
$query = [
|
||||||
|
'access_token' => $this->getAccessToken(),
|
||||||
|
'openid' => $openid,
|
||||||
|
'lang' => 'zh_CN'
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->request->setMethod(WxClient::GET);
|
||||||
|
$this->request->setIsSSL(true);
|
||||||
|
return $this->request->get($this->publicInfo, $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $encryptedData
|
* @param $encryptedData
|
||||||
|
|||||||
@@ -396,4 +396,27 @@ class Config
|
|||||||
return $this->key;
|
return $this->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $configs
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setConfigs(array $configs)
|
||||||
|
{
|
||||||
|
if (empty($configs)) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
foreach ($configs as $key => $val) {
|
||||||
|
if (empty($val) || is_array($val)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!property_exists($this, $key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->$key = $val;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,48 @@ class Message extends Miniprogarampage
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $media_id
|
||||||
|
* @param string $thumb_media_id
|
||||||
|
* @param string $title
|
||||||
|
* @param string $description
|
||||||
|
* @return Result
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function sendVideoNews(string $media_id, string $thumb_media_id, string $title, string $description)
|
||||||
|
{
|
||||||
|
$this->msgData['msgtype'] = 'video';
|
||||||
|
$this->msgData['video[media_id]'] = $media_id;
|
||||||
|
$this->msgData['video[thumb_media_id]'] = $thumb_media_id;
|
||||||
|
$this->msgData['video[title]'] = $title;
|
||||||
|
$this->msgData['video[description]'] = $description;
|
||||||
|
|
||||||
|
return $this->sendKefuMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $musicurl
|
||||||
|
* @param string $hqmusicurl
|
||||||
|
* @param string $thumb_media_id
|
||||||
|
* @param string $title
|
||||||
|
* @param string $description
|
||||||
|
* @return Result
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function sendMusicNews(string $musicurl, string $hqmusicurl, string $thumb_media_id, string $title, string $description)
|
||||||
|
{
|
||||||
|
$this->msgData['msgtype'] = 'music';
|
||||||
|
$this->msgData['music[title]'] = $title;
|
||||||
|
$this->msgData['music[description]'] = $description;
|
||||||
|
$this->msgData['music[musicurl]'] = $musicurl;
|
||||||
|
$this->msgData['music[hqmusicurl]'] = $hqmusicurl;
|
||||||
|
$this->msgData['music[thumb_media_id]'] = $thumb_media_id;
|
||||||
|
|
||||||
|
return $this->sendKefuMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $head_content
|
* @param string $head_content
|
||||||
* @param string $tail_content
|
* @param string $tail_content
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ abstract class Miniprogarampage
|
|||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/** @var mixed $instance */
|
/** @var mixed $instance */
|
||||||
private static $instance = null;
|
protected static $instance = null;
|
||||||
|
|
||||||
/** @var WxClient */
|
/** @var WxClient */
|
||||||
protected $request = null;
|
protected $request = null;
|
||||||
|
|||||||
+596
@@ -0,0 +1,596 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace wchat;
|
||||||
|
|
||||||
|
|
||||||
|
class Notify extends Miniprogarampage
|
||||||
|
{
|
||||||
|
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']);
|
||||||
|
|
||||||
|
$nowSign = Help::sign($params, $this->config->getKey(), $sign['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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: whwyy
|
||||||
|
* Date: 2018/4/8 0008
|
||||||
|
* Time: 9:49
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace wchat;
|
||||||
|
|
||||||
|
class PublicTemplate extends Miniprogarampage
|
||||||
|
{
|
||||||
|
|
||||||
|
private $keywords = [];
|
||||||
|
private $templateId = '';
|
||||||
|
private $first = '';
|
||||||
|
private $remark = '';
|
||||||
|
private $openId = '';
|
||||||
|
private $defaultUrl = 'http://weixin.qq.com/download';
|
||||||
|
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send';
|
||||||
|
private $miniprogram = [];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 $name
|
||||||
|
* @param $context
|
||||||
|
* @param string $color
|
||||||
|
*/
|
||||||
|
public function replaceKeyword($name, $context, $color = '')
|
||||||
|
{
|
||||||
|
$this->keywords[$name] = ['value' => $context, 'color' => $color];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param $context
|
||||||
|
* @param null $color
|
||||||
|
*/
|
||||||
|
public function addKeyword($name, $context, $color = null)
|
||||||
|
{
|
||||||
|
if (empty($color)) {
|
||||||
|
$color = '#000';
|
||||||
|
}
|
||||||
|
$this->keywords[$name] = [
|
||||||
|
'value' => $context,
|
||||||
|
'color' => $color
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $context
|
||||||
|
* @param string $color
|
||||||
|
*/
|
||||||
|
public function setFirst($context, $color = '#f00')
|
||||||
|
{
|
||||||
|
$this->first = [
|
||||||
|
'value' => $context,
|
||||||
|
'color' => $color
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $context
|
||||||
|
* @param string $color
|
||||||
|
*/
|
||||||
|
public function setRemark($context, $color = '#000')
|
||||||
|
{
|
||||||
|
$this->remark = [
|
||||||
|
'value' => $context,
|
||||||
|
'color' => $color
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $appid
|
||||||
|
* @param $pagepath
|
||||||
|
*/
|
||||||
|
public function setMiniprogram($appid, $pagepath)
|
||||||
|
{
|
||||||
|
$this->miniprogram = [
|
||||||
|
'appid' => $appid,
|
||||||
|
'pagepath' => $pagepath
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Result
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* 奴隶交易通知
|
||||||
|
*/
|
||||||
|
public function sendTemplate()
|
||||||
|
{
|
||||||
|
$url = $this->sendUrl . '?access_token=' . $this->getAccessToken();
|
||||||
|
|
||||||
|
$keywords = $this->keywords;
|
||||||
|
$keywords['first'] = $this->first;
|
||||||
|
$keywords['remark'] = $this->remark;
|
||||||
|
|
||||||
|
$default = [
|
||||||
|
"touser" => $this->openId,
|
||||||
|
"template_id" => $this->templateId,
|
||||||
|
"url" => $this->defaultUrl,
|
||||||
|
"data" => $keywords,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($this->miniprogram)) {
|
||||||
|
$default['miniprogram'] = $this->miniprogram;
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = json_encode($default, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
|
$this->request->setIsSSL(true);
|
||||||
|
$this->request->addHeader('content-type', 'application/json');
|
||||||
|
|
||||||
|
$result = $this->request->post($url, $params);
|
||||||
|
$result->append('postBody', $params);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
+50
-44
@@ -35,41 +35,56 @@ class Recharge extends Miniprogarampage
|
|||||||
$this->orderNo = $orderNo;
|
$this->orderNo = $orderNo;
|
||||||
$this->data['openid'] = $openId;
|
$this->data['openid'] = $openId;
|
||||||
|
|
||||||
$this->request->setCallback([$this, 'payCallback']);
|
$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) || $sign != $_sign) {
|
||||||
|
$return['code'] = -1;
|
||||||
|
$return['message'] = $data['return_msg'] ?? '返回数据签名验证失败';
|
||||||
|
} 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 $return;
|
||||||
|
});
|
||||||
return $this->send($this->unifiedorder, $this->builder());
|
return $this->send($this->unifiedorder, $this->builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $result
|
* 'appId' => $result['appid'],
|
||||||
* @param $body
|
* 'nonceStr' => $result['nonce_str'],
|
||||||
|
* 'package' => 'prepay_id=' . $result['prepay_id'],
|
||||||
|
* 'signType' => 'MD5',
|
||||||
|
* 'timeStamp' => (string)time(),
|
||||||
|
* @param $prepay_id
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function payCallback($result, $body)
|
public function reception($prepay_id)
|
||||||
{
|
{
|
||||||
$data = Help::toArray($result);
|
$array = [
|
||||||
if (isset($data['sign'])) {
|
'appId' => $this->config->getAppid(),
|
||||||
$sign = $data['sign'];
|
'nonceStr' => Help::random(32),
|
||||||
unset($data['sign']);
|
'package' => 'prepay_id=' . $prepay_id,
|
||||||
}
|
'signType' => 'MD5',
|
||||||
$return = [];
|
'timeStamp' => (string)time(),
|
||||||
$_sign = Help::sign($data, $this->config->getKey(), $this->config->getSignType());
|
];
|
||||||
if (!isset($sign) || $sign != $_sign) {
|
$key = $this->config->getKey();
|
||||||
$return['code'] = -1;
|
$sign_type = $this->config->getSignType();
|
||||||
$return['message'] = $data['return_msg'] ?? '返回数据签名验证失败';
|
$array['paySign'] = Help::sign($array, $key, $sign_type);
|
||||||
} else {
|
return $array;
|
||||||
$return['code'] = 0;
|
|
||||||
$return['data'] = $data;
|
|
||||||
$return['data']['postBody'] = $body;
|
|
||||||
if ($data['return_code'] == 'FAIL') {
|
|
||||||
$return['code'] = -1;
|
|
||||||
$return['message'] = $data['return_msg'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -125,7 +140,15 @@ class Recharge extends Miniprogarampage
|
|||||||
$sign_type = $this->config->getSignType();
|
$sign_type = $this->config->getSignType();
|
||||||
$array['sign'] = Help::sign($array, $key, $sign_type);
|
$array['sign'] = Help::sign($array, $key, $sign_type);
|
||||||
|
|
||||||
$this->request->setCallback([$this, 'txCallback']);
|
$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));
|
return $this->send($this->transfers, Help::toXml($array));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,21 +165,4 @@ class Recharge extends Miniprogarampage
|
|||||||
$this->request->addHeader('Content-Type', 'text/xml');
|
$this->request->addHeader('Content-Type', 'text/xml');
|
||||||
return $this->request->send($url, $data);
|
return $this->request->send($url, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $data
|
|
||||||
* @return Result
|
|
||||||
* 提现回调
|
|
||||||
*/
|
|
||||||
public function txCallback($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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,15 @@ class Wx
|
|||||||
return Template::getInstance($this->config);
|
return Template::getInstance($this->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PublicTemplate
|
||||||
|
*/
|
||||||
|
public function getPublicTemplate()
|
||||||
|
{
|
||||||
|
return PublicTemplate::getInstance($this->config);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Account
|
* @return Account
|
||||||
*/
|
*/
|
||||||
@@ -74,4 +83,12 @@ class Wx
|
|||||||
{
|
{
|
||||||
return Recharge::getInstance($this->config);
|
return Recharge::getInstance($this->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getNotify()
|
||||||
|
{
|
||||||
|
return Notify::getInstance($this->config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -128,7 +128,7 @@ class WxClient
|
|||||||
|
|
||||||
$client = $this->getClient($this->getHostPort(), $url, $data);
|
$client = $this->getClient($this->getHostPort(), $url, $data);
|
||||||
if ($client->statusCode < 0) {
|
if ($client->statusCode < 0) {
|
||||||
throw new \Exception('连接错误!');
|
throw new \Exception($client->errMsg);
|
||||||
}
|
}
|
||||||
$body = $client->body;
|
$body = $client->body;
|
||||||
$client->close();
|
$client->close();
|
||||||
@@ -141,7 +141,8 @@ class WxClient
|
|||||||
*/
|
*/
|
||||||
private function getHostIp()
|
private function getHostIp()
|
||||||
{
|
{
|
||||||
return array_shift(\Co::getAddrInfo($this->host));
|
$host = \Co::getAddrInfo($this->host);
|
||||||
|
return array_shift($host);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,7 +164,6 @@ class WxClient
|
|||||||
private function getClient($port, $url, $data)
|
private function getClient($port, $url, $data)
|
||||||
{
|
{
|
||||||
$host = $this->getHostIp();
|
$host = $this->getHostIp();
|
||||||
|
|
||||||
$client = new Client($host, $port, $this->isSSL);
|
$client = new Client($host, $port, $this->isSSL);
|
||||||
if (!empty($this->header)) {
|
if (!empty($this->header)) {
|
||||||
$client->setHeaders($this->header);
|
$client->setHeaders($this->header);
|
||||||
@@ -247,7 +247,7 @@ class WxClient
|
|||||||
private function structure($body, $_data)
|
private function structure($body, $_data)
|
||||||
{
|
{
|
||||||
$this->setIsSSL(false);
|
$this->setIsSSL(false);
|
||||||
$this->setHeaders(null);
|
$this->setHeaders([]);
|
||||||
|
|
||||||
if ($this->callback !== NULL) {
|
if ($this->callback !== NULL) {
|
||||||
$result = call_user_func($this->callback, $body, $_data);
|
$result = call_user_func($this->callback, $body, $_data);
|
||||||
|
|||||||
Reference in New Issue
Block a user