Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
-43
@@ -35,40 +35,71 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 string
|
* @return string
|
||||||
@@ -125,7 +156,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 +181,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
|
||||||
*/
|
*/
|
||||||
|
|||||||
+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