21 Commits

Author SHA1 Message Date
as2252258@163.com 26e691fec8 add clear 2019-08-21 13:37:26 +08:00
as2252258@163.com 00f046fba1 add clear 2019-08-21 13:34:03 +08:00
as2252258@163.com ad78b85ea0 add clear 2019-08-21 13:27:12 +08:00
as2252258@163.com a4e504e5e3 add clear 2019-08-21 13:23:11 +08:00
as2252258@163.com 706088998b add clear 2019-08-21 13:22:22 +08:00
as2252258@163.com cf52645c42 add clear 2019-08-21 13:20:56 +08:00
as2252258@163.com 8e27dc41e5 add clear 2019-08-21 12:13:02 +08:00
as2252258@163.com 5202270073 add clear 2019-08-21 12:11:36 +08:00
as2252258@163.com 93e763c880 add clear 2019-08-21 11:55:42 +08:00
as2252258@163.com 6136633a83 add clear 2019-08-21 11:54:20 +08:00
as2252258@163.com fa67c60088 add clear 2019-08-19 16:17:45 +08:00
as2252258@163.com fecac0e850 add clear 2019-08-19 16:14:36 +08:00
as2252258@163.com 1b89cd61ae add clear 2019-08-19 16:13:24 +08:00
as2252258@163.com a1c85376e1 add clear 2019-08-19 16:07:44 +08:00
as2252258@163.com c323b97112 add clear 2019-08-19 15:51:29 +08:00
as2252258@163.com 663bf23ebd add clear 2019-07-19 19:11:12 +08:00
as2252258@163.com d769ba0aaa add clear 2019-07-19 18:09:58 +08:00
as2252258@163.com e44b1c0989 add clear 2019-07-19 18:09:42 +08:00
as2252258@163.com b24d18dc55 add clear 2019-07-19 17:53:54 +08:00
as2252258@163.com cc87f8b440 Merge remote-tracking branch 'origin/master' 2019-07-19 17:50:59 +08:00
as2252258@163.com 4de90eff88 add clear 2019-07-19 17:50:49 +08:00
8 changed files with 317 additions and 48 deletions
+19
View File
@@ -12,6 +12,7 @@ class Account extends Miniprogarampage
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 $publicInfo = 'https://api.weixin.qq.com/cgi-bin/user/info?';
private $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
private $savePath = __DIR__ . '/../../../';
@@ -48,6 +49,24 @@ class Account extends Miniprogarampage
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
+23
View File
@@ -396,4 +396,27 @@ class Config
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;
}
}
+42
View File
@@ -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 $tail_content
+1 -1
View File
@@ -15,7 +15,7 @@ abstract class Miniprogarampage
protected $config;
/** @var mixed $instance */
private static $instance = null;
protected static $instance = null;
/** @var WxClient */
protected $request = null;
+154
View File
@@ -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;
}
}
+53 -31
View File
@@ -35,25 +35,15 @@ class Recharge extends Miniprogarampage
$this->orderNo = $orderNo;
$this->data['openid'] = $openId;
$this->request->setCallback([$this, 'payCallback']);
return $this->send($this->unifiedorder, $this->builder());
}
/**
* @param $result
* @param $body
* @return array
*/
public function payCallback($result, $body)
{
$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, $this->config->getKey(), $this->config->getSignType());
$_sign = Help::sign($data, $config->getKey(), $config->getSignType());
if (!isset($sign) || $sign != $_sign) {
$return['code'] = -1;
$return['message'] = $data['return_msg'] ?? '返回数据签名验证失败';
@@ -67,8 +57,49 @@ class Recharge extends Miniprogarampage
}
}
return $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);
return $array;
}
/**
* @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
@@ -125,7 +156,15 @@ class Recharge extends Miniprogarampage
$sign_type = $this->config->getSignType();
$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));
}
@@ -142,21 +181,4 @@ class Recharge extends Miniprogarampage
$this->request->addHeader('Content-Type', 'text/xml');
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);
}
}
+9
View File
@@ -51,6 +51,15 @@ class Wx
return Template::getInstance($this->config);
}
/**
* @return PublicTemplate
*/
public function getPublicTemplate()
{
return PublicTemplate::getInstance($this->config);
}
/**
* @return Account
*/
+4 -4
View File
@@ -128,7 +128,7 @@ class WxClient
$client = $this->getClient($this->getHostPort(), $url, $data);
if ($client->statusCode < 0) {
throw new \Exception('连接错误!');
throw new \Exception($client->errMsg);
}
$body = $client->body;
$client->close();
@@ -141,7 +141,8 @@ class WxClient
*/
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)
{
$host = $this->getHostIp();
$client = new Client($host, $port, $this->isSSL);
if (!empty($this->header)) {
$client->setHeaders($this->header);
@@ -247,7 +247,7 @@ class WxClient
private function structure($body, $_data)
{
$this->setIsSSL(false);
$this->setHeaders(null);
$this->setHeaders([]);
if ($this->callback !== NULL) {
$result = call_user_func($this->callback, $body, $_data);