Compare commits
No commits in common. 'dcd2845f6102f1287130cb7a5ecef61b7dbe1661' and 'c491ba926da32e6a77d105745a93061a098b0b29' have entirely different histories.
dcd2845f61
...
c491ba926d
@ -1,4 +1 @@
|
||||
/runtime/
|
||||
.env
|
||||
.idea
|
||||
.Ds_Store
|
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-installer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-sae" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/pclzip/pclzip" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-worker" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpexcel/PHPExcel" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-image" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-mongo" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/prophecy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/zendframework/zend-escaper" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/diff" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/global-state" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/comparator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/environment" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/exporter" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-docblock" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/type-resolver" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-common" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/instantiator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpoffice/phpspreadsheet" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpoffice/phpword" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/yaml" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpoffice/common" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/dom-crawler" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpoffice/phpexcel" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/workerman/workerman" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/simple-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-timer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-file-iterator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-text-template" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-testing" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/markbaker/matrix" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit-mock-objects" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-helper" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/markbaker/complex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-code-coverage" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-queue" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-token-stream" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/topthink/think-migration" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/crm_php.iml" filepath="$PROJECT_DIR$/.idea/crm_php.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\wework\api;
|
||||
|
||||
use think\Cache;
|
||||
|
||||
class Api {
|
||||
/**
|
||||
* @var object 对象实例
|
||||
*/
|
||||
protected static $instance;
|
||||
protected static $baseUrl = 'https://qyapi.weixin.qq.com/cgi-bin/';
|
||||
|
||||
protected static $getAccessToken = 'gettoken';
|
||||
protected static $contactInfo = 'externalcontact/get';
|
||||
|
||||
protected $corpId = '';
|
||||
protected $corpSecret = '';
|
||||
|
||||
protected $accessToken = '';
|
||||
|
||||
function __construct($corpId, $corpSecret)
|
||||
{
|
||||
$this->corpId = $corpId;
|
||||
$this->corpSecret = $corpSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户详情
|
||||
* @param $externalUserId
|
||||
* @return mixed
|
||||
*/
|
||||
function contactInfo($externalUserId) {
|
||||
return $this->get(self::$contactInfo, [
|
||||
'access_token' => $this->getAccessToken(),
|
||||
'external_userid' => $externalUserId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取accessToken
|
||||
* @return false|mixed
|
||||
*/
|
||||
protected function getAccessToken() {
|
||||
if ($this->accessToken == '') {
|
||||
$this->accessToken = Cache::get('accessToken:' . $this->corpId);
|
||||
if ($this->accessToken == '') {
|
||||
$result = $this->get(self::$getAccessToken, [
|
||||
'corpid' => $this->corpId,
|
||||
'corpsecret' => $this->corpSecret
|
||||
]);
|
||||
if (isset($result['access_token']) && $result['access_token']) {
|
||||
Cache::set('accessToken:' . $this->corpId, $result['access_token'],$result['expires_in']-60);
|
||||
$this->accessToken = $result['access_token'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function get($action, $data) {
|
||||
return json_decode(Curl::get(self::$baseUrl . $action,null,$data), true);
|
||||
}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
<?php
|
||||
namespace app\common\wework\api;
|
||||
class Curl
|
||||
{
|
||||
/**
|
||||
*curl post请求
|
||||
* @param $url
|
||||
* @param null $header
|
||||
* @param null $data
|
||||
* @param bool $isHeader
|
||||
* @return mixed
|
||||
*/
|
||||
public static function post($url, $header = null, $data = null, $isHeader = false)
|
||||
{
|
||||
return self::curl('post', $url, $header, $data, $isHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
*curl put请求
|
||||
* @param $url
|
||||
* @param null $header
|
||||
* @param null $data
|
||||
* @param bool $isHeader
|
||||
* @return mixed
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function put($url, $header = null, $data = null, $isHeader = false)
|
||||
{
|
||||
return self::curl('put', $url, $header, $data, $isHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
*curl get请求
|
||||
* @param $url
|
||||
* @param null $header
|
||||
* @param null $data
|
||||
* @param bool $isHeader
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($url, $header = null, $data = null, $isHeader = false)
|
||||
{
|
||||
if ($data) {
|
||||
if (is_array($data)) {
|
||||
$data = http_build_query($data);
|
||||
}
|
||||
if (strpos($url, '?') === false) {
|
||||
$url = $url . '?' . $data;
|
||||
} else {
|
||||
$url = $url . '&' . $data;
|
||||
}
|
||||
}
|
||||
return self::curl('get', $url, $header, null, $isHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
*curl请求
|
||||
* @param $method
|
||||
* @param $url
|
||||
* @param null $header
|
||||
* @param null $data
|
||||
* @param bool $isHeader
|
||||
* @return mixed
|
||||
*/
|
||||
public static function curl($method, $url, $header = null, $data = null, $isHeader = false)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if ($header) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
//curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
|
||||
if (stripos($url, "https://") !== FALSE) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
}
|
||||
|
||||
if ($data) {
|
||||
if (is_array($data)) {
|
||||
$sets = array();
|
||||
foreach ($data as $key => $val) {
|
||||
$sets[] = $key . '=' . urlencode($val);
|
||||
}
|
||||
$data = implode('&', $sets);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
|
||||
$method = strtolower($method);
|
||||
if ('post' == $method) {
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
} elseif ('put' == $method) {
|
||||
//curl_setopt($ch,CURLOPT_PUT,true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
}
|
||||
// curl_setopt($ch, CURLOPT_PROXY, "socks5://127.0.0.1:18080");
|
||||
|
||||
//获取头部信息
|
||||
if ($isHeader) {
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
}
|
||||
|
||||
$output = curl_exec($ch);
|
||||
if ($output === false) {
|
||||
var_dump(curl_error($ch));
|
||||
}
|
||||
curl_close($ch);
|
||||
return $output;
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
namespace app\common\wework\callback;
|
||||
/**
|
||||
* error code 说明.
|
||||
* <ul>
|
||||
* <li>-40001: 签名验证错误</li>
|
||||
* <li>-40002: xml解析失败</li>
|
||||
* <li>-40003: sha加密生成签名失败</li>
|
||||
* <li>-40004: encodingAesKey 非法</li>
|
||||
* <li>-40005: corpid 校验错误</li>
|
||||
* <li>-40006: aes 加密失败</li>
|
||||
* <li>-40007: aes 解密失败</li>
|
||||
* <li>-40008: 解密后得到的buffer非法</li>
|
||||
* <li>-40009: base64加密失败</li>
|
||||
* <li>-40010: base64解密失败</li>
|
||||
* <li>-40011: 生成xml失败</li>
|
||||
* </ul>
|
||||
*/
|
||||
class ErrorCode
|
||||
{
|
||||
public static $OK = 0;
|
||||
public static $ValidateSignatureError = -40001;
|
||||
public static $ParseXmlError = -40002;
|
||||
public static $ComputeSignatureError = -40003;
|
||||
public static $IllegalAesKey = -40004;
|
||||
public static $ValidateCorpidError = -40005;
|
||||
public static $EncryptAESError = -40006;
|
||||
public static $DecryptAESError = -40007;
|
||||
public static $IllegalBuffer = -40008;
|
||||
public static $EncodeBase64Error = -40009;
|
||||
public static $DecodeBase64Error = -40010;
|
||||
public static $GenReturnXmlError = -40011;
|
||||
}
|
||||
|
||||
?>
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
namespace app\common\wework\callback;
|
||||
|
||||
/**
|
||||
* PKCS7Encoder class
|
||||
*
|
||||
* 提供基于PKCS7算法的加解密接口.
|
||||
*/
|
||||
class PKCS7Encoder
|
||||
{
|
||||
public static $block_size = 32;
|
||||
|
||||
/**
|
||||
* 对需要加密的明文进行填充补位
|
||||
* @param $text 需要进行填充补位操作的明文
|
||||
* @return 补齐明文字符串
|
||||
*/
|
||||
function encode($text)
|
||||
{
|
||||
$block_size = PKCS7Encoder::$block_size;
|
||||
$text_length = strlen($text);
|
||||
//计算需要填充的位数
|
||||
$amount_to_pad = PKCS7Encoder::$block_size - ($text_length % PKCS7Encoder::$block_size);
|
||||
if ($amount_to_pad == 0) {
|
||||
$amount_to_pad = PKCS7Encoder::block_size;
|
||||
}
|
||||
//获得补位所用的字符
|
||||
$pad_chr = chr($amount_to_pad);
|
||||
$tmp = "";
|
||||
for ($index = 0; $index < $amount_to_pad; $index++) {
|
||||
$tmp .= $pad_chr;
|
||||
}
|
||||
return $text . $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对解密后的明文进行补位删除
|
||||
* @param decrypted 解密后的明文
|
||||
* @return 删除填充补位后的明文
|
||||
*/
|
||||
function decode($text)
|
||||
{
|
||||
|
||||
$pad = ord(substr($text, -1));
|
||||
if ($pad < 1 || $pad > PKCS7Encoder::$block_size) {
|
||||
$pad = 0;
|
||||
}
|
||||
return substr($text, 0, (strlen($text) - $pad));
|
||||
}
|
||||
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
<?php
|
||||
namespace app\common\wework\callback;
|
||||
|
||||
/**
|
||||
* Prpcrypt class
|
||||
*
|
||||
* 提供接收和推送给公众平台消息的加解密接口.
|
||||
*/
|
||||
class Prpcrypt
|
||||
{
|
||||
public $key = null;
|
||||
public $iv = null;
|
||||
|
||||
/**
|
||||
* Prpcrypt constructor.
|
||||
* @param $k
|
||||
*/
|
||||
public function __construct($k)
|
||||
{
|
||||
$this->key = base64_decode($k . '=');
|
||||
$this->iv = substr($this->key, 0, 16);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param $text
|
||||
* @param $receiveId
|
||||
* @return array
|
||||
*/
|
||||
public function encrypt($text, $receiveId)
|
||||
{
|
||||
try {
|
||||
//拼接
|
||||
$text = $this->getRandomStr() . pack('N', strlen($text)) . $text . $receiveId;
|
||||
//添加PKCS#7填充
|
||||
$pkc_encoder = new PKCS7Encoder;
|
||||
$text = $pkc_encoder->encode($text);
|
||||
//加密
|
||||
if (function_exists('openssl_encrypt')) {
|
||||
$encrypted = openssl_encrypt($text, 'AES-256-CBC', $this->key, OPENSSL_ZERO_PADDING, $this->iv);
|
||||
} else {
|
||||
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, base64_decode($text), MCRYPT_MODE_CBC, $this->iv);
|
||||
}
|
||||
return array(ErrorCode::$OK, $encrypted);
|
||||
} catch (Exception $e) {
|
||||
print $e;
|
||||
return array(MyErrorCode::$EncryptAESError, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param $encrypted
|
||||
* @param $receiveId
|
||||
* @return array
|
||||
*/
|
||||
public function decrypt($encrypted, $receiveId)
|
||||
{
|
||||
try {
|
||||
//解密
|
||||
if (function_exists('openssl_decrypt')) {
|
||||
$decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', $this->key, OPENSSL_ZERO_PADDING, $this->iv);
|
||||
} else {
|
||||
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, base64_decode($encrypted), MCRYPT_MODE_CBC, $this->iv);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return array(ErrorCode::$DecryptAESError, null);
|
||||
}
|
||||
try {
|
||||
//删除PKCS#7填充
|
||||
$pkc_encoder = new PKCS7Encoder;
|
||||
$result = $pkc_encoder->decode($decrypted);
|
||||
if (strlen($result) < 16) {
|
||||
return array();
|
||||
}
|
||||
//拆分
|
||||
$content = substr($result, 16, strlen($result));
|
||||
$len_list = unpack('N', substr($content, 0, 4));
|
||||
$xml_len = $len_list[1];
|
||||
$xml_content = substr($content, 4, $xml_len);
|
||||
$from_receiveId = substr($content, $xml_len + 4);
|
||||
} catch (Exception $e) {
|
||||
print $e;
|
||||
return array(ErrorCode::$IllegalBuffer, null);
|
||||
}
|
||||
if ($from_receiveId != $receiveId) {
|
||||
return array(ErrorCode::$ValidateCorpidError, null);
|
||||
}
|
||||
return array(0, $xml_content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机字符串
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRandomStr()
|
||||
{
|
||||
$str = '';
|
||||
$str_pol = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyl';
|
||||
$max = strlen($str_pol) - 1;
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$str .= $str_pol[mt_rand(0, $max)];
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
namespace app\common\wework\callback;
|
||||
|
||||
/**
|
||||
* SHA1 class
|
||||
*
|
||||
* 计算公众平台的消息签名接口.
|
||||
*/
|
||||
class SHA1
|
||||
{
|
||||
/**
|
||||
* 用SHA1算法生成安全签名
|
||||
* @param string $token 票据
|
||||
* @param string $timestamp 时间戳
|
||||
* @param string $nonce 随机字符串
|
||||
* @param string $encrypt 密文消息
|
||||
*/
|
||||
public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
|
||||
{
|
||||
//排序
|
||||
try {
|
||||
$array = array($encrypt_msg, $token, $timestamp, $nonce);
|
||||
sort($array, SORT_STRING);
|
||||
$str = implode($array);
|
||||
return array(ErrorCode::$OK, sha1($str));
|
||||
} catch (Exception $e) {
|
||||
print $e . "\n";
|
||||
return array(ErrorCode::$ComputeSignatureError, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
namespace app\common\wework\callback;
|
||||
|
||||
/**
|
||||
* XMLParse class
|
||||
*
|
||||
* 提供提取消息格式中的密文及生成回复消息格式的接口.
|
||||
*/
|
||||
class XMLParse
|
||||
{
|
||||
|
||||
/**
|
||||
* 提取出xml数据包中的加密消息
|
||||
* @param string $xmltext 待提取的xml字符串
|
||||
* @return string 提取出的加密消息字符串
|
||||
*/
|
||||
public function extract($xmltext)
|
||||
{
|
||||
try {
|
||||
$xml = new \DOMDocument();
|
||||
$xml->loadXML($xmltext);
|
||||
$array_e = $xml->getElementsByTagName('Encrypt');
|
||||
$encrypt = $array_e->item(0)->nodeValue;
|
||||
return array(0, $encrypt);
|
||||
} catch (Exception $e) {
|
||||
print $e . "\n";
|
||||
return array(ErrorCode::$ParseXmlError, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成xml消息
|
||||
* @param string $encrypt 加密后的消息密文
|
||||
* @param string $signature 安全签名
|
||||
* @param string $timestamp 时间戳
|
||||
* @param string $nonce 随机字符串
|
||||
*/
|
||||
public function generate($encrypt, $signature, $timestamp, $nonce)
|
||||
{
|
||||
$format = "<xml>
|
||||
<Encrypt><![CDATA[%s]]></Encrypt>
|
||||
<MsgSignature><![CDATA[%s]]></MsgSignature>
|
||||
<TimeStamp>%s</TimeStamp>
|
||||
<Nonce><![CDATA[%s]]></Nonce>
|
||||
</xml>";
|
||||
return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Test
|
||||
/*
|
||||
$sPostData = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><AgentID><![CDATA[toAgentID]]></AgentID><Encrypt><![CDATA[msg_encrypt]]></Encrypt></xml>";
|
||||
$xmlparse = new XMLParse;
|
||||
$array = $xmlparse->extract($sPostData);
|
||||
var_dump($array);
|
||||
*/
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in new issue