Browse Source

smsbao

master
ZLW-PC\Administrator 6 years ago
parent
commit
bd71f843fe
  1. 7
      README.md
  2. 184
      app/Common/Wechat/WechatAuth.php
  3. 2
      app/Common/Wechat/WechatCallbackApi.php
  4. 2
      app/Common/Wechat/WechatMenu.php
  5. 12
      app/Common/Wechat/WxComponent.php
  6. 2
      app/Common/Wechat/aes/demo.php
  7. 2
      app/Common/Wechat/aes/errorCode.php
  8. 34
      app/Common/Wechat/aes/pkcs7Encoder.php
  9. 4
      app/Common/Wechat/aes/sha1.php
  10. 81
      app/Common/Wechat/aes/wxBizDataCrypt.php
  11. 9
      app/Common/Wechat/aes/wxBizMsgCrypt.php
  12. 6
      app/Common/Wechat/aes/xmlparse.php
  13. 103
      app/Common/WechatAuth.php
  14. 4
      app/Common/aes/ReadMe.txt
  15. 2
      app/Http/Controllers/Admin/WeixinMenuController.php
  16. 50
      app/Http/Controllers/Api/ImageController.php
  17. 4
      app/Http/Controllers/Api/NotifyController.php
  18. 2
      app/Http/Controllers/Weixin/UserController.php
  19. 86
      app/Http/Service/Smsbao.php
  20. BIN
      public/images/pcscreenshots1.jpg
  21. BIN
      public/images/pcscreenshots2.jpg

7
README.md

@ -3,8 +3,15 @@
PC端 PC端
PC企业站
![alt text](/public/images/screenshots.jpg "网站截图") ![alt text](/public/images/screenshots.jpg "网站截图")
PC商城
![alt text](/public/images/pcscreenshots1.jpg "网站截图")
![alt text](/public/images/pcscreenshots2.jpg "网站截图")
WAP端 WAP端
![alt text](/public/images/wapscreenshots.png "手机站截图") ![alt text](/public/images/wapscreenshots.png "手机站截图")

184
app/Common/Wechat/WechatAuth.php

@ -0,0 +1,184 @@
<?php
namespace App\Common\Wechat;
/**
* OAuth2.0微信授权登录实现/微信PC扫码授权登录
* 微信/PC扫码登录,两种的方式是一样的,先跳转到微信网页获取code,通过code获取token,通过token获取用户信息
*/
class WechatAuth
{
//高级功能->开发者模式->获取
private $app_id;
private $app_secret;
public function __construct($app_id, $app_secret)
{
$this->app_id = $app_id;
$this->app_secret = $app_secret;
}
/**
* 获取微信授权链接
*
* @param string $redirect_uri 回调地址,授权后重定向的回调链接地址,请使用urlEncode对链接进行处理
* @param mixed $state 可以为空,重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
*/
public function get_authorize_url($redirect_uri = '', $state = '')
{
return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->app_id."&redirect_uri=".urlencode($redirect_uri)."&response_type=code&scope=snsapi_userinfo&state=".$state."#wechat_redirect";
}
/**
* 微信PC扫码授权登录链接
*
* @param string $redirect_uri 回调地址,授权后重定向的回调链接地址,请使用urlEncode对链接进行处理
* @param mixed $state 可以为空,重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
*/
public function get_qrconnect_url($redirect_uri = '', $state = '')
{
return "https://open.weixin.qq.com/connect/qrconnect?appid".$this->app_id."&redirect_uri=".urlencode($redirect_uri)."&response_type=code&scope=snsapi_login&state=".$state."#wechat_redirect";
}
/**
* 获取授权token
*
* @param string $code 通过get_authorize_url获取到的code
*/
public function get_access_token($code = '')
{
$token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->app_id}&secret={$this->app_secret}&code={$code}&grant_type=authorization_code";
$token_data = $this->http($token_url);
return json_decode($token_data, true);
}
/**
* 获取access_token,access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。
*/
public function get_token()
{
$token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->app_id}&secret={$this->app_secret}";
$token_data = $this->http($token_url);
return json_decode($token_data, true);
}
/**
* 获取小程序码,适用于需要的码数量较少的业务场景,通过该接口生成的小程序码,永久有效,数量限制见文末说明,请谨慎使用。
* @param string $path 不能为空,最大长度 128 字节
* @param int $width 二维码的宽度,默认430
*/
public function getwxacode($path, $width = 430)
{
$access_token = $this->get_token();
$url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token='.$access_token['access_token'];
$path ="pages/mine/mine/mine?query=1";
$data ='{"path":"'.$path.'","width":'.$width.'}';
$res = $this->http($url, $data);
return $res;
//将生成的小程序码存入相应文件夹下
//file_put_contents('./public/wxyido/img/'.time().'.jpg',$return);
}
/**
* 获取小程序码,通过该接口生成的小程序码,永久有效,数量暂无限制。用户扫描该码进入小程序后,开发者需在对应页面获取的码中 scene 字段的值,再做处理逻辑。
* @param string $data['scene'] 二维码场景值
* @param string $data['page'] 必须是已经发布的小程序存在的页面(否则报错),例如 "pages/index/index" ,根路径前不要填加'/',不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面
* @param int $data['width'] 二维码的宽度,默认430
* @param int $data['type'] 0路径存储,1base64
*/
public function getwxacodeunlimit($data)
{
$access_token = $this->get_token();
$url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$access_token['access_token'];
$post_data = array();
$post_data['scene'] = $data['scene'];
$post_data['page'] = $data['page'];
$post_data['width'] = $data['width'];
$res = $this->http($url, json_encode($post_data));
if($data['type']==0)
{
file_put_contents($data['image_path'], $res);
}
else
{
$res = $this->data_uri($res);
}
return $res;
//将生成的小程序码存入相应文件夹下
//file_put_contents('./public/wxyido/img/'.time().'.jpg',$res);
}
public function data_uri($contents, $mime = 'image/png')
{
$base64 = base64_encode($contents);
return ('data:' . $mime . ';base64,' . $base64);
}
/**
* 获取授权后的微信用户信息
*
* @param string $access_token
* @param string $open_id
*/
public function get_user_info($access_token = '', $open_id = '')
{
$info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$open_id}&lang=zh_CN";
$info_data = $this->http($info_url);
return json_decode($info_data, true);
}
/**
* 获取用户基本信息(包括UnionID机制)
*
* @param string $access_token
* @param string $open_id
*/
public function get_user_unionid($access_token = '', $open_id = '')
{
$info_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$access_token}&openid={$open_id}&lang=zh_CN";
$info_data = $this->http($info_url);
return json_decode($info_data, true);
}
/**
* 小程序登录凭证校验
* 小程序调用wx.login() 获取 临时登录凭证code ,并回传到开发者服务器。
* 开发者服务器以code换取 用户唯一标识openid 会话密钥session_key。
* 临时登录凭证校验接口是一个 HTTPS 接口,开发者服务器使用 临时登录凭证code 获取 session_key openid 等。
* @param string $js_code 小程序登录时获取的code
*/
public function miniprogram_wxlogin($js_code)
{
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->app_id}&secret={$this->app_secret}&js_code=$js_code&grant_type=authorization_code";
$res = $this->http($url);
return json_decode($res, true);
}
// cURL函数简单封装
public function http($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data))
{
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}

2
app/Common/WechatCallbackApi.php → app/Common/Wechat/WechatCallbackApi.php

@ -1,5 +1,5 @@
<?php <?php
namespace App\Common;
namespace App\Common\Wechat;
/** /**
* 微信自定义菜单-响应菜单点击事件 * 微信自定义菜单-响应菜单点击事件

2
app/Common/WechatMenu.php → app/Common/Wechat/WechatMenu.php

@ -1,5 +1,5 @@
<?php <?php
namespace App\Common;
namespace App\Common\Wechat;
/** /**
* 微信自定义菜单 * 微信自定义菜单

12
app/Common/WxComponent.php → app/Common/Wechat/WxComponent.php

@ -1,5 +1,5 @@
<?php <?php
namespace App\Common;
namespace App\Common\Wechat;
if (!class_exists("WXBizMsgCrypt")) if (!class_exists("WXBizMsgCrypt"))
{ {
@ -63,8 +63,8 @@ class WxComponent
* @param string $component_appid 平台appId * @param string $component_appid 平台appId
* @param string $component_appsecret 平台appsecret * @param string $component_appsecret 平台appsecret
* @param string $component_verify_ticket 平台票据,微信服务器定时推送过来 * @param string $component_verify_ticket 平台票据,微信服务器定时推送过来
* @param string $encodingAesKey 公众号消息加解密Key
* @param string $token 公众号消息校验Token
* @param string $encodingAesKey 公众号消息加解密Key,公众平台上,开发者设置的EncodingAESKey
* @param string $token 公众号消息校验Token,公众平台上,开发者设置的token
*/ */
public function __construct($component_appid, $component_appsecret, $component_verify_ticket, $encodingAesKey, $token) public function __construct($component_appid, $component_appsecret, $component_verify_ticket, $encodingAesKey, $token)
{ {
@ -141,16 +141,16 @@ class WxComponent
/** /**
* 获得预授权码 * 获得预授权码
* @param $access_token
* @param $component_access_token
* @return bool|mixed{ * @return bool|mixed{
* "pre_auth_code":"Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw", * "pre_auth_code":"Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
* "expires_in":600 * "expires_in":600
* } * }
*/ */
public function getPreauthCode($access_token)
public function getPreauthCode($component_access_token)
{ {
$arr = array('component_appid' => $this->component_appid); $arr = array('component_appid' => $this->component_appid);
$result = $this->httpPost(self::API_URL_PREFIX . self::GET_PREAUTHCODE_URL . $access_token, json_encode($arr));
$result = $this->httpPost(self::API_URL_PREFIX . self::GET_PREAUTHCODE_URL . $component_access_token, json_encode($arr));
if ($result) { if ($result) {
$json = json_decode($result, true); $json = json_decode($result, true);
if (!$json || !empty($json['errcode'])) { if (!$json || !empty($json['errcode'])) {

2
app/Common/aes/demo.php → app/Common/Wechat/aes/demo.php

@ -37,4 +37,4 @@ if ($errCode == 0) {
print("解密后: " . $msg . "\n"); print("解密后: " . $msg . "\n");
} else { } else {
print($errCode . "\n"); print($errCode . "\n");
}
}

2
app/Common/aes/errorCode.php → app/Common/Wechat/aes/errorCode.php

@ -1,5 +1,4 @@
<?php <?php
/** /**
* error code 说明. * error code 说明.
* <ul> * <ul>
@ -31,5 +30,4 @@ class ErrorCode
public static $DecodeBase64Error = -40010; public static $DecodeBase64Error = -40010;
public static $GenReturnXmlError = -40011; public static $GenReturnXmlError = -40011;
} }
?> ?>

34
app/Common/aes/pkcs7Encoder.php → app/Common/Wechat/aes/pkcs7Encoder.php

@ -1,5 +1,4 @@
<?php <?php
include_once "errorCode.php"; include_once "errorCode.php";
/** /**
@ -10,7 +9,7 @@ include_once "errorCode.php";
class PKCS7Encoder class PKCS7Encoder
{ {
public static $block_size = 32; public static $block_size = 32;
/** /**
* 对需要加密的明文进行填充补位 * 对需要加密的明文进行填充补位
* @param $text 需要进行填充补位操作的明文 * @param $text 需要进行填充补位操作的明文
@ -33,7 +32,7 @@ class PKCS7Encoder
} }
return $text . $tmp; return $text . $tmp;
} }
/** /**
* 对解密后的明文进行补位删除 * 对解密后的明文进行补位删除
* @param decrypted 解密后的明文 * @param decrypted 解密后的明文
@ -41,11 +40,13 @@ class PKCS7Encoder
*/ */
function decode($text) function decode($text)
{ {
$pad = ord(substr($text, -1)); $pad = ord(substr($text, -1));
if ($pad < 1 || $pad > 32) {
if ($pad < 1 || $pad > 32)
{
$pad = 0; $pad = 0;
} }
return substr($text, 0, (strlen($text) - $pad)); return substr($text, 0, (strlen($text) - $pad));
} }
} }
@ -58,12 +59,12 @@ class PKCS7Encoder
class Prpcrypt class Prpcrypt
{ {
public $key; public $key;
function __construct($k) function __construct($k)
{ {
$this->key = base64_decode($k . "="); $this->key = base64_decode($k . "=");
} }
/** /**
* 对明文进行加密 * 对明文进行加密
* @param string $text 需要加密的明文 * @param string $text 需要加密的明文
@ -71,7 +72,6 @@ class Prpcrypt
*/ */
public function encrypt($text, $appid) public function encrypt($text, $appid)
{ {
try { try {
//获得16位随机字符串,填充到明文之前 //获得16位随机字符串,填充到明文之前
$random = $this->getRandomStr(); $random = $this->getRandomStr();
@ -97,7 +97,7 @@ class Prpcrypt
return array(ErrorCode::$EncryptAESError, null); return array(ErrorCode::$EncryptAESError, null);
} }
} }
/** /**
* 对密文进行解密 * 对密文进行解密
* @param string $encrypted 需要解密的密文 * @param string $encrypted 需要解密的密文
@ -105,7 +105,6 @@ class Prpcrypt
*/ */
public function decrypt($encrypted, $appid) public function decrypt($encrypted, $appid)
{ {
try { try {
//使用BASE64对需要解密的字符串进行解码 //使用BASE64对需要解密的字符串进行解码
$ciphertext_dec = base64_decode($encrypted); $ciphertext_dec = base64_decode($encrypted);
@ -120,8 +119,7 @@ class Prpcrypt
} catch (Exception $e) { } catch (Exception $e) {
return array(ErrorCode::$DecryptAESError, null); return array(ErrorCode::$DecryptAESError, null);
} }
try { try {
//去除补位字符 //去除补位字符
$pkc_encoder = new PKCS7Encoder; $pkc_encoder = new PKCS7Encoder;
@ -141,26 +139,24 @@ class Prpcrypt
if ($from_appid != $appid) if ($from_appid != $appid)
return array(ErrorCode::$ValidateAppidError, null); return array(ErrorCode::$ValidateAppidError, null);
return array(0, $xml_content); return array(0, $xml_content);
} }
/** /**
* 随机生成16位字符串 * 随机生成16位字符串
* @return string 生成的字符串 * @return string 生成的字符串
*/ */
function getRandomStr() function getRandomStr()
{ {
$str = ""; $str = "";
$str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; $str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($str_pol) - 1; $max = strlen($str_pol) - 1;
for ($i = 0; $i < 16; $i++) {
for ($i = 0; $i < 16; $i++)
{
$str .= $str_pol[mt_rand(0, $max)]; $str .= $str_pol[mt_rand(0, $max)];
} }
return $str; return $str;
} }
} }
?> ?>

4
app/Common/aes/sha1.php → app/Common/Wechat/aes/sha1.php

@ -1,5 +1,4 @@
<?php <?php
include_once "errorCode.php"; include_once "errorCode.php";
/** /**
@ -29,8 +28,5 @@ class SHA1
return array(ErrorCode::$ComputeSignatureError, null); return array(ErrorCode::$ComputeSignatureError, null);
} }
} }
} }
?> ?>

81
app/Common/Wechat/aes/wxBizDataCrypt.php

@ -0,0 +1,81 @@
<?php
/**
* 对微信小程序用户加密数据的解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
*/
/**
* error code 说明.
* <ul>
* <li>-41001: encodingAesKey 非法</li>
* <li>-41003: aes 解密失败</li>
* <li>-41004: 解密后得到的buffer非法</li>
* <li>-41005: base64加密失败</li>
* <li>-41016: base64解密失败</li>
* </ul>
*/
class ErrorCode
{
public static $OK = 0;
public static $IllegalAesKey = -41001;
public static $IllegalIv = -41002;
public static $IllegalBuffer = -41003;
public static $DecodeBase64Error = -41004;
}
class WXBizDataCrypt
{
private $appid;
private $sessionKey;
/**
* 构造函数
* @param $sessionKey string 用户在小程序登录后获取的会话密钥
* @param $appid string 小程序的appid
*/
public function __construct( $appid, $sessionKey)
{
$this->sessionKey = $sessionKey;
$this->appid = $appid;
}
/**
* 检验数据的真实性,并且获取解密后的明文.
* @param $encryptedData string 加密的用户数据
* @param $iv string 与用户数据一同返回的初始向量
* @param $data string 解密后的原文
*
* @return int 成功0,失败返回对应的错误码
*/
public function decryptData( $encryptedData, $iv, &$data )
{
if (strlen($this->sessionKey) != 24) {
return ErrorCode::$IllegalAesKey;
}
$aesKey=base64_decode($this->sessionKey);
if (strlen($iv) != 24) {
return ErrorCode::$IllegalIv;
}
$aesIV=base64_decode($iv);
$aesCipher=base64_decode($encryptedData);
$result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
$dataObj=json_decode( $result );
if( $dataObj == NULL )
{
return ErrorCode::$IllegalBuffer;
}
if( $dataObj->watermark->appid != $this->appid )
{
return ErrorCode::$IllegalBuffer;
}
$data = $result;
return ErrorCode::$OK;
}
}

9
app/Common/aes/wxBizMsgCrypt.php → app/Common/Wechat/aes/wxBizMsgCrypt.php

@ -1,12 +1,10 @@
<?php <?php
/** /**
* 对公众平台发送给公众账号的消息加解密示例代码. * 对公众平台发送给公众账号的消息加解密示例代码.
* *
* @copyright Copyright (c) 1998-2014 Tencent Inc. * @copyright Copyright (c) 1998-2014 Tencent Inc.
*/ */
include_once "sha1.php"; include_once "sha1.php";
include_once "xmlparse.php"; include_once "xmlparse.php";
include_once "pkcs7Encoder.php"; include_once "pkcs7Encoder.php";
@ -81,8 +79,7 @@ class WXBizMsgCrypt
$encryptMsg = $xmlparse->generate($encrypt, $signature, $timeStamp, $nonce); $encryptMsg = $xmlparse->generate($encrypt, $signature, $timeStamp, $nonce);
return ErrorCode::$OK; return ErrorCode::$OK;
} }
/** /**
* 检验消息的真实性,并且获取解密后的明文. * 检验消息的真实性,并且获取解密后的明文.
* <ol> * <ol>
@ -145,6 +142,4 @@ class WXBizMsgCrypt
return ErrorCode::$OK; return ErrorCode::$OK;
} }
}
}

6
app/Common/aes/xmlparse.php → app/Common/Wechat/aes/xmlparse.php

@ -8,7 +8,6 @@ include_once "errorCode.php";
*/ */
class XMLParse class XMLParse
{ {
/** /**
* 提取出xml数据包中的加密消息 * 提取出xml数据包中的加密消息
* @param string $xmltext 待提取的xml字符串 * @param string $xmltext 待提取的xml字符串
@ -29,7 +28,7 @@ class XMLParse
return array(ErrorCode::$ParseXmlError, null, null); return array(ErrorCode::$ParseXmlError, null, null);
} }
} }
/** /**
* 生成xml消息 * 生成xml消息
* @param string $encrypt 加密后的消息密文 * @param string $encrypt 加密后的消息密文
@ -47,8 +46,5 @@ class XMLParse
</xml>"; </xml>";
return sprintf($format, $encrypt, $signature, $timestamp, $nonce); return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
} }
} }
?> ?>

103
app/Common/WechatAuth.php

@ -1,103 +0,0 @@
<?php
namespace App\Common;
/**
* OAuth2.0微信授权登录实现/微信PC扫码授权登录
* 微信/PC扫码登录,两种的方式是一样的,先跳转到微信网页获取code,通过code获取token,通过token获取用户信息
*/
class WechatAuth
{
//高级功能->开发者模式->获取
private $app_id;
private $app_secret;
public function __construct($app_id, $app_secret)
{
$this->app_id = $app_id;
$this->app_secret = $app_secret;
}
/**
* 获取微信授权链接
*
* @param string $redirect_uri 回调地址,授权后重定向的回调链接地址,请使用urlEncode对链接进行处理
* @param mixed $state 可以为空,重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
*/
public function get_authorize_url($redirect_uri = '', $state = '')
{
return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->app_id."&redirect_uri=".urlencode($redirect_uri)."&response_type=code&scope=snsapi_userinfo&state=".$state."#wechat_redirect";
}
/**
* 微信PC扫码授权登录链接
*
* @param string $redirect_uri 回调地址,授权后重定向的回调链接地址,请使用urlEncode对链接进行处理
* @param mixed $state 可以为空,重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
*/
public function get_qrconnect_url($redirect_uri = '', $state = '')
{
return "https://open.weixin.qq.com/connect/qrconnect?appid".$this->app_id."&redirect_uri=".urlencode($redirect_uri)."&response_type=code&scope=snsapi_login&state=".$state."#wechat_redirect";
}
/**
* 获取授权token
*
* @param string $code 通过get_authorize_url获取到的code
*/
public function get_access_token($code = '')
{
$token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->app_id}&secret={$this->app_secret}&code={$code}&grant_type=authorization_code";
$token_data = $this->http($token_url);
return json_decode($token_data, true);
}
/**
* 获取授权后的微信用户信息
*
* @param string $access_token
* @param string $open_id
*/
public function get_user_info($access_token = '', $open_id = '')
{
$info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$open_id}&lang=zh_CN";
$info_data = $this->http($info_url);
return json_decode($info_data, true);
}
/**
* 获取用户基本信息(包括UnionID机制)
*
* @param string $access_token
* @param string $open_id
*/
public function get_user_unionid($access_token = '', $open_id = '')
{
$info_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$access_token}&openid={$open_id}&lang=zh_CN";
$info_data = $this->http($info_url);
return json_decode($info_data, true);
}
// cURL函数简单封装
public function http($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data))
{
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}

4
app/Common/aes/ReadMe.txt

@ -1,4 +0,0 @@
注意事项:
1.WXBizMsgCrypt.php文件提供了WXBizMsgCrypt类的实现,是用户接入企业微信的接口类。Sample.php提供了示例以供开发者参考。errorCode.php, pkcs7Encoder.php, sha1.php, xmlparse.php文件是实现这个类的辅助类,开发者无须关心其具体实现。
2.WXBizMsgCrypt类封装了 DecryptMsg, EncryptMsg两个接口,分别用于开发者解密以及开发者回复消息的加密。使用方法可以参考Sample.php文件。
3.加解密协议请参考微信公众平台官方文档。

2
app/Http/Controllers/Admin/WeixinMenuController.php

@ -6,7 +6,7 @@ use App\Common\Helper;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Logic\WeixinMenuLogic; use App\Http\Logic\WeixinMenuLogic;
use App\Http\Model\WeixinMenu; use App\Http\Model\WeixinMenu;
use App\Common\WechatMenu;
use App\Common\Wechat\WechatMenu;
class WeixinMenuController extends CommonController class WeixinMenuController extends CommonController
{ {

50
app/Http/Controllers/Api/ImageController.php

@ -207,4 +207,54 @@ class ImageController extends CommonController
return $fileArray; return $fileArray;
} }
/**
* base64图片上传,成功返回路径,不含域名,只能单图上传
* @param string img base64字符串
* @return string
*/
public function base64ImageUpload(Request $request)
{
$res = [];
$base64_img = $_POST['img'];
if($base64_img)
{
if(preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_img, $result))
{
$type = $result[2];
if(in_array($type, array('jpeg','jpg','gif','bmp','png')))
{
$image_path = $this->path.'/'.date('Ymdhis',time()).rand(1000,9999).'.'.$type;
$uploads_path = $this->path; //存储路径
if(!file_exists($this->public_path.$uploads_path))
{
Helper::createDir($this->public_path.$uploads_path); //创建文件夹;
}
if(file_put_contents($this->public_path.$image_path, base64_decode(str_replace($result[1], '', $base64_img))))
{
return ReturnData::create(ReturnData::SUCCESS,null,$image_path);
}
else
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'图片上传失败');
}
}
else
{
//文件类型错误
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'图片上传类型错误');
}
}
else
{
//文件错误
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件错误');
}
}
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'请上传文件');
}
} }

4
app/Http/Controllers/Api/NotifyController.php

@ -24,7 +24,9 @@ class NotifyController extends CommonController
Log::info('微信支付回调数据:'.$GLOBALS['HTTP_RAW_POST_DATA']); Log::info('微信支付回调数据:'.$GLOBALS['HTTP_RAW_POST_DATA']);
//获取通知的数据 //获取通知的数据
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
//$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
$xml = file_get_contents("php://input");
//将XML转为array //将XML转为array
//禁止引用外部xml实体 //禁止引用外部xml实体
libxml_disable_entity_loader(true); libxml_disable_entity_loader(true);

2
app/Http/Controllers/Weixin/UserController.php

@ -5,7 +5,7 @@ use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Common\ReturnCode; use App\Common\ReturnCode;
use App\Common\ReturnData; use App\Common\ReturnData;
use App\Common\WechatAuth;
use App\Common\Wechat\WechatAuth;
use App\Common\Helper; use App\Common\Helper;
class UserController extends CommonController class UserController extends CommonController

86
app/Http/Service/Smsbao.php

@ -0,0 +1,86 @@
<?php
namespace App\Http\Service;
/**
* 短信宝
*/
class Smsbao
{
private $user_name;
private $password;
private $smsapi = "http://api.smsbao.com/";
private $status_str = array(
"0" => "短信发送成功",
"-1" => "参数不全",
"-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
"30" => "密码错误",
"40" => "账号不存在",
"41" => "余额不足",
"42" => "帐户已过期",
"43" => "IP地址限制",
"50" => "内容含有敏感词"
);
public function __construct($user_name, $password)
{
$this->user_name = $user_name;
$this->password = $password;
}
/**
* 国内短信
*
* @param string $sms_content 要发送的短信内容
* @param string $sms_phone 接收的手机号,单发:15205201314,群发:15205201314,15205201315,群发时多个手机号以逗号分隔,一次不要超过99个号码
* return string
*/
public function sms($sms_content, $sms_phone)
{
$user = $this->user_name; //短信平台帐号
$pass = md5($this->password); //短信平台密码
$content = $sms_content; //要发送的短信内容
$phone = $sms_phone; //要发送短信的手机号码
$sendurl = $this->smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
$result = file_get_contents($sendurl) ;
return $this->status_str[$result];
}
/**
* 国际短信
*
* @param string $sms_content 要发送的短信内容
* @param string $sms_phone 接收的手机号,单发:+60901234567,群发:+60901234567,+60901234567,群发时多个手机号以逗号分隔,一次不要超过99个号码,注:国际号码需包含国际地区前缀号码,格式必须是"+"号开头("+"号需要urlencode处理,如:urlencode("+60901234567")否则会出现格式错误)
* return string
*/
public function wsms($sms_content, $sms_phone)
{
$user = $this->user_name; //短信平台帐号
$pass = md5($this->password); //短信平台密码
$content = $sms_content; //要发送的短信内容
$phone = $sms_phone; //要发送短信的手机号码
$sendurl = $this->smsapi."wsms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
$result = file_get_contents($sendurl) ;
return $this->status_str[$result];
}
/**
* 语音验证码发送
*
* @param string $sms_code 发送的验证码
* @param string $sms_phone 目标手机号码
* return string
*/
public function voice($sms_code, $sms_phone)
{
$user = $this->user_name; //短信平台帐号
$pass = md5($this->password); //短信平台密码
$content = $sms_code; //要发送的短信内容
$phone = $sms_phone; //要发送短信的手机号码
$sendurl = $this->smsapi."voice?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
$result = file_get_contents($sendurl) ;
return $this->status_str[$result];
}
}

BIN
public/images/pcscreenshots1.jpg

Binary file not shown.

After

Width: 1076  |  Height: 937  |  Size: 136 KiB

BIN
public/images/pcscreenshots2.jpg

Binary file not shown.

After

Width: 1082  |  Height: 943  |  Size: 78 KiB

Loading…
Cancel
Save