Commit 96434d90 authored by 杨培's avatar 杨培

Merge remote-tracking branch 'origin/master'

parents 2ccbd2a7 16ea5523
...@@ -9,5 +9,32 @@ return [ ...@@ -9,5 +9,32 @@ return [
'msg.userid' => '78', 'msg.userid' => '78',
'msg.account' => '276147613x', 'msg.account' => '276147613x',
'msg.password' => '276147613', 'msg.password' => '276147613',
'msg.signature' => '【最课堂】' 'msg.signature' => '【最课堂】',
'alipay' => [
'partner' => '2088701843067550',
'seller_id' => '2088701843067550',
'key' => '12vr33u4g314hytde3g81oao9dfdarm6',
'notify_url' => 'http://商户网址/create_direct_pay_by_user-PHP-UTF-8/notify_url.php',
'return_url' => 'http://商户网址/create_direct_pay_by_user-PHP-UTF-8/return_url.php',
'sign_type' => strtoupper('MD5'),
'input_charset' => strtolower('utf-8'),
'cacert' => getcwd() . '\\cacert.pem',
'transport' => 'http',
'payment_type' => '1',
'service' => 'create_direct_pay_by_user',
],
// 'weixinpay'=>[
// 'appid'=>'wx180521eb22e9d7af',
// 'mchid'=>'1295461001',
// 'key'=>'ejg0l9phOAkp021qB54shz0Q8Tiscwzy',
// 'appsecret'=>'f20293c9548c469fb8b855fc98c4ef3c',
//
// ]
'weixinpay' => [
'appid' => 'wx5714a24a60083b2a',
'mchid' => '1399794002',
'key' => '8934e7d15453e97507ef794cf7b0519d',
'appsecret' => '7c18222c6ec31efa65d21606a629585d',
]
]; ];
...@@ -146,4 +146,48 @@ class Utils ...@@ -146,4 +146,48 @@ class Utils
return $count; return $count;
} }
/**
* @param $rootElementName
* @param $ar
* @return mixed
*/
public static function assocArrayToXML($rootElementName, $ar)
{
if ($rootElementName === NULL) {
$xml = new \SimpleXMLElement("<?xml version=\"1.0\"?>");
} else {
$xml = new \SimpleXMLElement("<?xml version=\"1.0\"?><{$rootElementName}></{$rootElementName}>");
}
$f = create_function('$f,$c,$a', '
foreach($a as $k=>$v) {
if(is_array($v)) {
$ch=$c->addChild($k);
$f($f,$ch,$v);
} else {
$c->addChild($k,$v);
}
}');
$f($f, $xml, $ar);
return $xml->asXML();
}
/**
* xml to array
* @param $xml
* @return bool|mixed
*/
public static function xmlToArray($xml)
{
if (!$xml) {
return FALSE;
}
//将XML转为array
//禁止引用外部xml实体
libxml_disable_entity_loader(TRUE);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), TRUE);
}
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 下午4:51
*/
namespace common\libs;
use dosamigos\qrcode\formats\Wifi;
class WeixinPay
{
const UNIFIEDORDER = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
const NOTIFY_URL = "http://c.pp.cc/pay/weixin-notify";
private $appid;
private $mchid;
private $appsecret;
private $key;
private static $instance = NULL;
public function __construct($appid, $mchid, $appsecret, $key)
{
$this->appid = $appid;
$this->mchid = $mchid;
$this->appsecret = $appsecret;
$this->key = $key;
}
/**
* @return WeixinPay|null
*/
public static function getInstance()
{
if (self::$instance === NULL) {
$weixinpay = \Yii::$app->params['weixinpay'];
self::$instance = new WeixinPay(
$weixinpay['appid'],
$weixinpay['mchid'],
$weixinpay['appsecret'],
$weixinpay['key']
);
}
return self::$instance;
}
/**
* 生成微信支付url
* @param $productId
* @return string
*/
public function makePayUrl($productId)
{
$data = [
'appid' => $this->appid,
'mch_id' => $this->mchid,
'time_stamp' => time(),
'nonce_str' => \Yii::$app->security->generateRandomString(16),
'sign' => '',
'product_id' => $productId
];
$data['sign'] = self::makeWeixinPaySign($data, $this->key);
return "weixin://wxpay/bizpayurl?" . self::toUrlParams($data, TRUE);
}
/**
* @param $data
* @param $key
* @return string
*/
public static function makeWeixinPaySign($data, $key)
{
//签名步骤一:按字典序排序参数
ksort($data);
$string = self::toUrlParams($data);
//签名步骤二:在string后加入KEY
$string = $string . "&key=" . $key;
//签名步骤三:MD5加密
$string = md5($string);
//签名步骤四:所有字符转为大写
$result = strtoupper($string);
return $result;
}
/**
* @param $data
* @param bool $signFliter 默认过滤sign true 不过滤
* @return string
*/
private static function toUrlParams($data, $signFliter = FALSE)
{
$buff = "";
foreach ($data as $k => $v) {
if (($signFliter or $k != "sign") && $v != "" && !is_array($v)) {
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/12
* Time: 上午10:24
*/
namespace common\libs\alipay;
use DOMDocument;
use yii\helpers\ArrayHelper;
require_once (dirname(__FILE__) . "/libs/alipay_core.function.php");
require_once(dirname(__FILE__) . "/libs/alipay_md5.function.php");
class AliPay
{
private $alipay_config;
/**
*支付宝网关地址(新)
*/
private $alipay_gateway_new = 'https://mapi.alipay.com/gateway.do?';
public function __construct()
{
$this->alipay_config = \Yii::$app->params['alipay'];
}
/**
* 生成签名结果
* @param $para_sort 已排序要签名的数组
* @return string
*/
function buildRequestMysign($para_sort)
{
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);
$mysign = "";
switch (strtoupper(trim($this->alipay_config['sign_type']))) {
case "MD5" :
$mysign = md5Sign($prestr, $this->alipay_config['key']);
break;
default :
$mysign = "";
}
return $mysign;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组
*/
function buildRequestPara($para_temp)
{
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//生成签名结果
$mysign = $this->buildRequestMysign($para_sort);
//签名结果与签名方式加入请求提交参数组中
$para_sort['sign'] = $mysign;
$para_sort['sign_type'] = strtoupper(trim($this->alipay_config['sign_type']));
return $para_sort;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组字符串
*/
function buildRequestParaToString($para_temp)
{
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
$request_data = createLinkstringUrlencode($para);
return $request_data;
}
/**
* 建立请求,以表单HTML形式构造(默认)
* @param $para_temp 请求参数数组
* @param $method 提交方式。两个值可选:post、get
* @param $button_name 确认按钮显示文字
* @return 提交表单HTML文本
*/
function buildRequestForm($para_temp, $method, $button_name)
{
//待请求参数数组
$para_temp = ArrayHelper::merge([
"service" => $this->alipay_config['service'],
"partner" => $this->alipay_config['partner'],
"seller_id" => $this->alipay_config['seller_id'],
"payment_type" => $this->alipay_config['payment_type'],
"return_url" => $this->alipay_config['return_url'],
"_input_charset" => trim(strtolower($this->alipay_config['input_charset']))
], $para_temp);
$para = $this->buildRequestPara($para_temp);
$sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='" . $this->alipay_gateway_new . "_input_charset=" . trim(strtolower($this->alipay_config['input_charset'])) . "' method='" . $method . "'>";
while (list ($key, $val) = each($para)) {
$sHtml .= "<input type='hidden' name='" . $key . "' value='" . $val . "'/>";
}
//submit按钮控件请不要含有name属性
$sHtml = $sHtml . "<input type='submit' value='" . $button_name . "' style='display:none;'></form>";
$sHtml = $sHtml . "<script>document.forms['alipaysubmit'].submit();</script>";
return $sHtml;
}
/**
* 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
* 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
* return 时间戳字符串
*/
function query_timestamp()
{
$url = $this->alipay_gateway_new . "service=query_timestamp&partner=" . trim(strtolower($this->alipay_config['partner'])) . "&_input_charset=" . trim(strtolower($this->alipay_config['input_charset']));
$encrypt_key = "";
$doc = new DOMDocument();
$doc->load($url);
$itemEncrypt_key = $doc->getElementsByTagName("encrypt_key");
$encrypt_key = $itemEncrypt_key->item(0)->nodeValue;
return $encrypt_key;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/12
* Time: 下午3:52
*/
namespace common\libs\alipay;
class AlipayNotify
{
/**
* HTTPS形式消息验证地址
*/
private $https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&';
/**
* HTTP形式消息验证地址
*/
private $http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?';
private $alipay_config;
function __construct()
{
$this->alipay_config = \Yii::$app->params['alipay'];
}
/**
* 针对notify_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyNotify()
{
if (empty($_POST)) {//判断POST来的数组是否为空
return FALSE;
} else {
//生成签名结果
$isSign = $this->getSignVeryfy($_POST, $_POST["sign"]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt = 'false';
if (!empty($_POST["notify_id"])) {
$responseTxt = $this->getResponse($_POST["notify_id"]);
}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_POST);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (preg_match("/true$/i", $responseTxt) && $isSign) {
return TRUE;
} else {
return FALSE;
}
}
}
/**
* 针对return_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyReturn()
{
if (empty($_GET)) {//判断POST来的数组是否为空
return FALSE;
} else {
//生成签名结果
$isSign = $this->getSignVeryfy($_GET, $_GET["sign"]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt = 'false';
if (!empty($_GET["notify_id"])) {
$responseTxt = $this->getResponse($_GET["notify_id"]);
}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n return_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_GET);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (preg_match("/true$/i", $responseTxt) && $isSign) {
return TRUE;
} else {
return FALSE;
}
}
}
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @return 签名验证结果
*/
function getSignVeryfy($para_temp, $sign)
{
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);
$isSgin = FALSE;
switch (strtoupper(trim($this->alipay_config['sign_type']))) {
case "MD5" :
$isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']);
break;
default :
$isSgin = FALSE;
}
return $isSgin;
}
/**
* 获取远程服务器ATN结果,验证返回URL
* @param $notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
function getResponse($notify_id)
{
$transport = strtolower(trim($this->alipay_config['transport']));
$partner = trim($this->alipay_config['partner']);
$veryfy_url = '';
if ($transport == 'https') {
$veryfy_url = $this->https_verify_url;
} else {
$veryfy_url = $this->http_verify_url;
}
$veryfy_url = $veryfy_url . "partner=" . $partner . "&notify_id=" . $notify_id;
$responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']);
return $responseTxt;
}
}
\ No newline at end of file
<?php
/* *
* 支付宝接口公用函数
* 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件
* 版本:3.3
* 日期:2012-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function createLinkstring($para) {
$arg = "";
while (list ($key, $val) = each ($para)) {
$arg.=$key."=".$val."&";
}
//去掉最后一个&字符
$arg = substr($arg,0,count($arg)-2);
//如果存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
return $arg;
}
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function createLinkstringUrlencode($para) {
$arg = "";
while (list ($key, $val) = each ($para)) {
$arg.=$key."=".urlencode($val)."&";
}
//去掉最后一个&字符
$arg = substr($arg,0,count($arg)-2);
//如果存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
return $arg;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
function paraFilter($para) {
$para_filter = array();
while (list ($key, $val) = each ($para)) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
function argSort($para) {
ksort($para);
reset($para);
return $para;
}
/**
* 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
* 注意:服务器需要开通fopen配置
* @param $word 要写入日志里的文本内容 默认值:空值
*/
function logResult($word='') {
$fp = fopen("log.txt","a");
flock($fp, LOCK_EX) ;
fwrite($fp,"执行日期:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n");
flock($fp, LOCK_UN);
fclose($fp);
}
/**
* 远程获取数据,POST模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* @param $para 请求的数据
* @param $input_charset 编码格式。默认值:空值
* return 远程输出的数据
*/
function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') {
if (trim($input_charset) != '') {
$url = $url."_input_charset=".$input_charset;
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址
curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
curl_setopt($curl,CURLOPT_POST,true); // post传输数据
curl_setopt($curl,CURLOPT_POSTFIELDS,$para);// post传输数据
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close($curl);
return $responseText;
}
/**
* 远程获取数据,GET模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* return 远程输出的数据
*/
function getHttpResponseGET($url,$cacert_url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close($curl);
return $responseText;
}
/**
* 实现多种字符编码方式
* @param $input 需要编码的字符串
* @param $_output_charset 输出的编码格式
* @param $_input_charset 输入的编码格式
* return 编码后的字符串
*/
function charsetEncode($input,$_output_charset ,$_input_charset) {
$output = "";
if(!isset($_output_charset) )$_output_charset = $_input_charset;
if($_input_charset == $_output_charset || $input ==null ) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
} elseif(function_exists("iconv")) {
$output = iconv($_input_charset,$_output_charset,$input);
} else die("sorry, you have no libs support for charset change.");
return $output;
}
/**
* 实现多种字符解码方式
* @param $input 需要解码的字符串
* @param $_output_charset 输出的解码格式
* @param $_input_charset 输入的解码格式
* return 解码后的字符串
*/
function charsetDecode($input,$_input_charset ,$_output_charset) {
$output = "";
if(!isset($_input_charset) )$_input_charset = $_input_charset ;
if($_input_charset == $_output_charset || $input ==null ) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
} elseif(function_exists("iconv")) {
$output = iconv($_input_charset,$_output_charset,$input);
} else die("sorry, you have no libs support for charset changes.");
return $output;
}
?>
\ No newline at end of file
<?php
/* *
* MD5
* 详细:MD5加密
* 版本:3.3
* 日期:2012-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 签名字符串
* @param $prestr 需要签名的字符串
* @param $key 私钥
* return 签名结果
*/
function md5Sign($prestr, $key) {
$prestr = $prestr . $key;
return md5($prestr);
}
/**
* 验证签名
* @param $prestr 需要签名的字符串
* @param $sign 签名结果
* @param $key 私钥
* return 签名结果
*/
function md5Verify($prestr, $sign, $key) {
$prestr = $prestr . $key;
$mysgin = md5($prestr);
if($mysgin == $sign) {
return true;
}
else {
return false;
}
}
?>
\ No newline at end of file
<?php
/* *
* 类名:AlipayNotify
* 功能:支付宝通知处理类
* 详细:处理支付宝各接口通知返回
* 版本:3.2
* 日期:2011-03-25
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考
*************************注意*************************
* 调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常
*/
require_once("alipay_core.function.php");
require_once("alipay_md5.function.php");
class AlipayNotify {
/**
* HTTPS形式消息验证地址
*/
var $https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&';
/**
* HTTP形式消息验证地址
*/
var $http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?';
var $alipay_config;
function __construct($alipay_config){
$this->alipay_config = $alipay_config;
}
function AlipayNotify($alipay_config) {
$this->__construct($alipay_config);
}
/**
* 针对notify_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyNotify(){
if(empty($_POST)) {//判断POST来的数组是否为空
return false;
}
else {
//生成签名结果
$isSign = $this->getSignVeryfy($_POST, $_POST["sign"]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt = 'false';
if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_POST);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (preg_match("/true$/i",$responseTxt) && $isSign) {
return true;
} else {
return false;
}
}
}
/**
* 针对return_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyReturn(){
if(empty($_GET)) {//判断POST来的数组是否为空
return false;
}
else {
//生成签名结果
$isSign = $this->getSignVeryfy($_GET, $_GET["sign"]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt = 'false';
if (! empty($_GET["notify_id"])) {$responseTxt = $this->getResponse($_GET["notify_id"]);}
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n return_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_GET);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (preg_match("/true$/i",$responseTxt) && $isSign) {
return true;
} else {
return false;
}
}
}
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @return 签名验证结果
*/
function getSignVeryfy($para_temp, $sign) {
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);
$isSgin = false;
switch (strtoupper(trim($this->alipay_config['sign_type']))) {
case "MD5" :
$isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']);
break;
default :
$isSgin = false;
}
return $isSgin;
}
/**
* 获取远程服务器ATN结果,验证返回URL
* @param $notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
function getResponse($notify_id) {
$transport = strtolower(trim($this->alipay_config['transport']));
$partner = trim($this->alipay_config['partner']);
$veryfy_url = '';
if($transport == 'https') {
$veryfy_url = $this->https_verify_url;
}
else {
$veryfy_url = $this->http_verify_url;
}
$veryfy_url = $veryfy_url."partner=" . $partner . "&notify_id=" . $notify_id;
$responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']);
return $responseTxt;
}
}
?>
<?php
/* *
* 类名:AlipaySubmit
* 功能:支付宝各接口请求提交类
* 详细:构造支付宝各接口表单HTML文本,获取远程HTTP数据
* 版本:3.3
* 日期:2012-07-23
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
require_once("alipay_core.function.php");
require_once("alipay_md5.function.php");
class AlipaySubmit {
var $alipay_config;
/**
*支付宝网关地址(新)
*/
var $alipay_gateway_new = 'https://mapi.alipay.com/gateway.do?';
function __construct($alipay_config){
$this->alipay_config = $alipay_config;
}
function AlipaySubmit($alipay_config) {
$this->__construct($alipay_config);
}
/**
* 生成签名结果
* @param $para_sort 已排序要签名的数组
* return 签名结果字符串
*/
function buildRequestMysign($para_sort) {
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);
$mysign = "";
switch (strtoupper(trim($this->alipay_config['sign_type']))) {
case "MD5" :
$mysign = md5Sign($prestr, $this->alipay_config['key']);
break;
default :
$mysign = "";
}
return $mysign;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组
*/
function buildRequestPara($para_temp) {
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//生成签名结果
$mysign = $this->buildRequestMysign($para_sort);
//签名结果与签名方式加入请求提交参数组中
$para_sort['sign'] = $mysign;
$para_sort['sign_type'] = strtoupper(trim($this->alipay_config['sign_type']));
return $para_sort;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组字符串
*/
function buildRequestParaToString($para_temp) {
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
$request_data = createLinkstringUrlencode($para);
return $request_data;
}
/**
* 建立请求,以表单HTML形式构造(默认)
* @param $para_temp 请求参数数组
* @param $method 提交方式。两个值可选:post、get
* @param $button_name 确认按钮显示文字
* @return 提交表单HTML文本
*/
function buildRequestForm($para_temp, $method, $button_name) {
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
$sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$this->alipay_gateway_new."_input_charset=".trim(strtolower($this->alipay_config['input_charset']))."' method='".$method."'>";
while (list ($key, $val) = each ($para)) {
$sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
}
//submit按钮控件请不要含有name属性
$sHtml = $sHtml."<input type='submit' value='".$button_name."' style='display:none;'></form>";
$sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>";
return $sHtml;
}
/**
* 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
* 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
* return 时间戳字符串
*/
function query_timestamp() {
$url = $this->alipay_gateway_new."service=query_timestamp&partner=".trim(strtolower($this->alipay_config['partner']))."&_input_charset=".trim(strtolower($this->alipay_config['input_charset']));
$encrypt_key = "";
$doc = new DOMDocument();
$doc->load($url);
$itemEncrypt_key = $doc->getElementsByTagName( "encrypt_key" );
$encrypt_key = $itemEncrypt_key->item(0)->nodeValue;
return $encrypt_key;
}
}
?>
\ No newline at end of file
...@@ -5,6 +5,7 @@ namespace common\models; ...@@ -5,6 +5,7 @@ namespace common\models;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use yii\helpers\HtmlPurifier; use yii\helpers\HtmlPurifier;
use yii\redis\ActiveQuery;
use yii\redis\ActiveRecord; use yii\redis\ActiveRecord;
/** /**
...@@ -30,8 +31,11 @@ class Course extends \yii\db\ActiveRecord ...@@ -30,8 +31,11 @@ class Course extends \yii\db\ActiveRecord
const STATUS_OK = 1; const STATUS_OK = 1;
const STATUS_FAILED = 2; const STATUS_FAILED = 2;
const STATUS_LOCKED = 3; const STATUS_LOCKED = 3;
const RECOMMEDN = 1;
const UN_RECOMMEND = 0;
public function formName() { public function formName()
{
return ''; return '';
} }
...@@ -41,13 +45,13 @@ class Course extends \yii\db\ActiveRecord ...@@ -41,13 +45,13 @@ class Course extends \yii\db\ActiveRecord
public function beforeSave($insert) public function beforeSave($insert)
{ {
if (!parent::beforeSave($insert)) { if (!parent::beforeSave($insert)) {
return false; return FALSE;
} }
$this->name = strip_tags($this->name); $this->name = strip_tags($this->name);
$this->intro = HtmlPurifier::process($this->intro); $this->intro = HtmlPurifier::process($this->intro);
return true; return TRUE;
} }
/** /**
...@@ -73,14 +77,14 @@ class Course extends \yii\db\ActiveRecord ...@@ -73,14 +77,14 @@ class Course extends \yii\db\ActiveRecord
{ {
return [ return [
[['name', 'preview_pic'], 'required'], [['name', 'preview_pic'], 'required'],
['name', 'string', 'length'=>[1,60]], ['name', 'string', 'length' => [1, 60]],
[['user_id', 'class_id'], 'integer'], [['user_id', 'class_id'], 'integer'],
['intro', 'string'], ['intro', 'string'],
['price', 'integer', 'min'=>0, 'max'=>9999], ['price', 'integer', 'min' => 0, 'max' => 9999],
['free_time', 'integer', 'min'=>0, 'max'=>15], ['free_time', 'integer', 'min' => 0, 'max' => 15],
['recommend', 'boolean'], ['recommend', 'boolean'],
['recommend', 'default', 'value'=>0], ['recommend', 'default', 'value' => 0],
['status', 'in', 'range'=>[0, 1, 2, 3]] ['status', 'in', 'range' => [0, 1, 2, 3]]
]; ];
} }
...@@ -114,7 +118,50 @@ class Course extends \yii\db\ActiveRecord ...@@ -114,7 +118,50 @@ class Course extends \yii\db\ActiveRecord
{ {
$query = self::find(); $query = self::find();
return $query->select('id,user_id,class_id,name,price,preview_pic,recommend,status,created_at,updated_at') return $query->select('id,user_id,class_id,name,price,preview_pic,recommend,status,created_at,updated_at')
->where(['id'=>$id])->asArray()->one(); ->where(['id' => $id])->asArray()->one();
}
/**
* 获取课程列表
* @param $classId
* @param $page 从0开始
* @param $num
* @return array
*/
public static function getCourseListsByClassId($classId, $page, $num)
{
$status = self::STATUS_OK;
$condition = "class_id=:class_id and status=$status";
$params = [':class_id' => $classId];
//获取总数
$count = self::find()->where($condition, $params)->count();
$start = $page * $num;
if ($count > 0) {
$data = self::find()->select('id,price,name,intro,preview_pic,recommend,created_at')->where($condition, $params)->limit($num)->offset($start)->with('teachers')->asArray()->all();
}
return [
'count' => $count,
'data' => $data
];
} }
/**
* 获取推荐的课程
* @param $classID
* @return array|\yii\db\ActiveRecord[]
*/
public static function getRecommendByClassId($classID)
{
$recommend = self::RECOMMEDN;
return self::find()->select('id,name,intro,preview_pic,recommend,created_at')->where("class_id=:class_id and recommend = $recommend", [':class_id' => $classID])->asArray()->all();
}
/**
* 获取关联的讲师信息
* @return $this
*/
public function getTeachers()
{
return $this->hasMany(Teacher::className(), ['id' => 'teacher_id'])->viaTable(CourseTeacher::tableName(), ['course_id' => 'id']);
}
} }
...@@ -23,6 +23,11 @@ use yii\db\ActiveRecord; ...@@ -23,6 +23,11 @@ use yii\db\ActiveRecord;
*/ */
class Courseware extends ActiveRecord class Courseware extends ActiveRecord
{ {
const STATUS_UNCHECK = 0;
const STATUS_OK = 1;
const STATUS_FAILED = 2;
const STATUS_LOCKED = 3;
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
...@@ -21,6 +21,11 @@ use yii\redis\ActiveRecord; ...@@ -21,6 +21,11 @@ use yii\redis\ActiveRecord;
*/ */
class Orders extends \yii\db\ActiveRecord class Orders extends \yii\db\ActiveRecord
{ {
//订单支付状体
const UNPAID = 0;
const PAID = 1;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -82,7 +87,7 @@ class Orders extends \yii\db\ActiveRecord ...@@ -82,7 +87,7 @@ class Orders extends \yii\db\ActiveRecord
* @param $userId * @param $userId
* @return array|\yii\db\ActiveRecord[] * @return array|\yii\db\ActiveRecord[]
*/ */
public static function getPurchasedCourseByUserId($userId) public static function findPurchasedCourseByUserId($userId)
{ {
$tableA = self::tableName(); $tableA = self::tableName();
$tableB = Course::tableName(); $tableB = Course::tableName();
...@@ -93,4 +98,19 @@ class Orders extends \yii\db\ActiveRecord ...@@ -93,4 +98,19 @@ class Orders extends \yii\db\ActiveRecord
} }
/**
* 判断是否存在订单号
* @param $userId
* @param $courseId
* @return array
*/
public static function findByUserIdAndCourseId($userId, $courseId)
{
return self::find()->select('*')->where('user_id=:user_id and course_id=:course_id', [
':user_id' => $userId,
':course_id' => $courseId
])->one();
}
} }
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
"yiisoft/yii2-swiftmailer": "*", "yiisoft/yii2-swiftmailer": "*",
"yiisoft/yii2-redis": "^2.0", "yiisoft/yii2-redis": "^2.0",
"guzzlehttp/guzzle": "^6.2", "guzzlehttp/guzzle": "^6.2",
"qiniu/php-sdk": "^7.0" "qiniu/php-sdk": "^7.0",
"light/yii2-xmlparser": "*",
"2amigos/yii2-qrcode-helper": "*"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-codeception": "*", "yiisoft/yii2-codeception": "*",
......
...@@ -4,9 +4,65 @@ ...@@ -4,9 +4,65 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "58c51098f2b70fd0b7cacfcb4527cb2f", "hash": "553e6afb2f94832a2b21ea5d6301d656",
"content-hash": "ed7bd775092a2dda1558bb321d31c8c4", "content-hash": "b2a9e1b6aa19ba113948022d2525b40b",
"packages": [ "packages": [
{
"name": "2amigos/yii2-qrcode-helper",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/2amigos/yii2-qrcode-helper.git",
"reference": "827a79d0e498026119c8cdcf724d81be2e0daa5f"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/2amigos/yii2-qrcode-helper/827a79d0e498026119c8cdcf724d81be2e0daa5f.zip",
"reference": "827a79d0e498026119c8cdcf724d81be2e0daa5f",
"shasum": ""
},
"require": {
"yiisoft/yii2": "*"
},
"require-dev": {
"phpunit/phpunit": "4.*",
"scrutinizer/ocular": "~1.1"
},
"type": "yii2-extension",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"dosamigos\\qrcode\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "2amigOS! Consulting Group",
"email": "hola@2amigos.us",
"homepage": "http://2amigos.us",
"role": "Developer"
}
],
"description": "Create QrCodes based on libqrencode C library.",
"keywords": [
"2amigos",
"extension",
"helper",
"qrcode",
"yii",
"yii 2",
"yii2"
],
"time": "2015-03-16 21:26:14"
},
{ {
"name": "bower-asset/bootstrap", "name": "bower-asset/bootstrap",
"version": "v3.3.7", "version": "v3.3.7",
...@@ -470,6 +526,52 @@ ...@@ -470,6 +526,52 @@
], ],
"time": "2016-06-24 23:00:38" "time": "2016-06-24 23:00:38"
}, },
{
"name": "light/yii2-xmlparser",
"version": "0.2.11",
"source": {
"type": "git",
"url": "https://github.com/lichunqiang/yii2-xmlparser.git",
"reference": "0e86c5d214dd04e28e4360de22aa1e2c7484e318"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/lichunqiang/yii2-xmlparser/0e86c5d214dd04e28e4360de22aa1e2c7484e318.zip",
"reference": "0e86c5d214dd04e28e4360de22aa1e2c7484e318",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "2.0.*"
},
"require-dev": {
"phpunit/phpunit": "4.4.*"
},
"type": "library",
"autoload": {
"psr-4": {
"light\\yii2\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "lichunqiang",
"email": "light-li@hotmail.com"
}
],
"description": "yii2 xml request parser",
"keywords": [
"parse",
"request",
"xml",
"yii2"
],
"time": "2015-08-15 16:07:34"
},
{ {
"name": "psr/http-message", "name": "psr/http-message",
"version": "1.0.1", "version": "1.0.1",
......
...@@ -18,7 +18,6 @@ class m160927_121107_course_init extends Migration ...@@ -18,7 +18,6 @@ class m160927_121107_course_init extends Migration
'id' => $this->primaryKey()->unsigned(), 'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(), 'user_id' => $this->integer()->notNull()->unsigned(),
'classed_id' => $this->integer()->notNull()->unsigned(), 'classed_id' => $this->integer()->notNull()->unsigned(),
'avatar' => $this->string(255)->notNull(),
'name' => $this->string(32)->notNull(), 'name' => $this->string(32)->notNull(),
'price' => $this->integer()->notNull(), 'price' => $this->integer()->notNull(),
'free_time' => $this->integer()->notNull(), 'free_time' => $this->integer()->notNull(),
......
...@@ -2,16 +2,24 @@ ...@@ -2,16 +2,24 @@
namespace frontend\controllers; namespace frontend\controllers;
use common\libs\alipay\AliPay;
use common\libs\WeixinPay;
use common\models\Classes;
use common\models\Comments; use common\models\Comments;
use common\models\Course; use common\models\Course;
use common\models\Courseware; use common\models\Courseware;
use common\models\Favorite; use common\models\Favorite;
use common\models\Orders;
use common\models\Support; use common\models\Support;
use dosamigos\qrcode\QrCode;
use GuzzleHttp\Client;
use Yii; use Yii;
use common\libs\Utils; use common\libs\Utils;
use yii\base\InvalidParamException; use yii\base\InvalidParamException;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\web\ForbiddenHttpException;
class HomeController extends \yii\web\Controller class HomeController extends \yii\web\Controller
{ {
...@@ -22,15 +30,15 @@ class HomeController extends \yii\web\Controller ...@@ -22,15 +30,15 @@ class HomeController extends \yii\web\Controller
*/ */
public function behaviors() public function behaviors()
{ {
return [ $rules = [
//权限限制 //权限限制
'access' => [ 'access' => [
'class' => AccessControl::className(), 'class' => AccessControl::className(),
'only' => ['support', 'favorite', 'comments'], 'only' => ['support', 'favorite', 'comments', 'pay'],
'rules' => [ 'rules' => [
[ [
'allow' => TRUE, 'allow' => TRUE,
'actions' => ['support', 'favorite'], 'actions' => ['support', 'favorite', 'pay'],
'roles' => ['@'], 'roles' => ['@'],
], ],
[ [
...@@ -43,14 +51,94 @@ class HomeController extends \yii\web\Controller ...@@ -43,14 +51,94 @@ class HomeController extends \yii\web\Controller
] ]
]; ];
return $rules;
}
/**
* 首页
* @param $classId 课堂id
* @return string
*/
public function actionIndex($classId)
{
$classInfo = Classes::findOne(['id' => $classId]);
if ($classInfo !== NULL) {
$classInfo = $classInfo->toArray();
return $this->render('index', [
'classInfo' => $classInfo
]);
} else {
throw new InvalidParamException('参数错误');
}
}
/**
* 获取课程列表
* @param $classId
* @param $page
* @param int $num
* @throws ForbiddenHttpException
*/
public function actionGetCourseLists($classId, $page, $num = 10)
{
if (Yii::$app->request->isAjax or TRUE) {
if ($page >= 0 and $num > 0) {
$result = Course::getCourseListsByClassId($classId, $page, $num);
} else {
throw new InvalidParamException('参数错误');
}
} else {
throw new ForbiddenHttpException('非法请求');
}
Utils::ajaxResponse(TRUE, 'ok', $result);
} }
public function actionIndex() /**
* 获取推荐的课程列表
* @param $classId
* @throws ForbiddenHttpException
*/
public function actionGetRecommendCourses($classId)
{ {
return $this->render('index');
if (Yii::$app->request->isAjax) {
$result = Course::getRecommendByClassId($classId);
} else {
throw new ForbiddenHttpException('非法请求');
}
Utils::ajaxResponse(TRUE, 'ok', $result);
} }
/**
* 视频播放
* @param $courseId
* @return string
*/
public function actionVideo($courseId)
{
$coursewareInfo = Courseware::findOne(['id' => $courseId, 'status' => Courseware::STATUS_OK]);
$course = Course::findOne(['id'=>$courseId]);
$teachers = $course->teachers;
if ($coursewareInfo === NULL) {
throw new InvalidParamException('参数错误');
} else {
$coursewareInfo = $coursewareInfo->toArray();
$coursewareInfo['previewUrl'] = Yii::$app->qiniu->getUrl('public', $course->preview_pic);
$coursewareInfo['intro'] = $course->intro;
$coursewareInfo['teachers'] = ArrayHelper::toArray($teachers);
$coursewareInfo['videoUrl'] = Yii::$app->qiniu->getUrl('video', $coursewareInfo['name']);
var_dump($coursewareInfo);
return $this->render('video', [
'coursewareInfo' => $coursewareInfo
]);
}
}
/** /**
* 点赞或者取消点赞 * 点赞或者取消点赞
* @param $coursewareId * @param $coursewareId
...@@ -153,4 +241,123 @@ class HomeController extends \yii\web\Controller ...@@ -153,4 +241,123 @@ class HomeController extends \yii\web\Controller
throw new \yii\web\ForbiddenHttpException('非法请求'); throw new \yii\web\ForbiddenHttpException('非法请求');
} }
} }
/**
* 支付宝支付请求
* @throws InvalidParamException
*/
public function actionPay($courseId)
{
$courseBaseInfo = Course::findBaseInfoByCourseId($courseId);
if ($courseBaseInfo !== NULL) {
$userId = Yii::$app->user->identity->getId();
$order = Orders::findByUserIdAndCourseId($userId, $courseId);
$price = $courseBaseInfo['price'];
$number = $this->generateOrderNumber($userId, $courseId, $price);
//判断订单是否存在
if ($order === NULL) {
$order = new Orders();
$order->user_id = $userId;
$order->course_id = $courseId;
$order->number = $number;
$order->credit = $price;
$order->status = Orders::UNPAID;
$order->pay_order = '0';
$order->save();
} else {
//价格变动后给支付宝的订单编号也会变动
if ($price !== $order->credit) {
$order->credit = $price;
$order->number = $number;
$order->update();
}
}
$alipay = new AliPay();
$parameter = array(
"out_trade_no" => $number,//订单号
"subject" => "购买课程-{$courseBaseInfo['name']}",//订单名称
"total_fee" => $price,//付款金额
"body" => '云崖购买',//商品描述
);
$html_text = $alipay->buildRequestForm($parameter, "get", "确认");
echo $html_text;
} else {
throw new InvalidParamException('参数错误');
}
}
/**
* 获取微信支付的二维码
*/
public function actionWeixinPayQrcode()
{
$userId = Yii::$app->user->identity->getId();
$courseBaseInfo = Course::findBaseInfoByCourseId($courseId);
if ($courseBaseInfo !== NULL) {
$price = $courseBaseInfo['price'];
$productId = $this->generateOrderNumber($userId, $courseId, $price);
$weixinPay = WeixinPay::getInstance();
return QrCode::jpg($weixinPay->makePayUrl($productId));
} else {
throw new InvalidParamException('参数错误');
}
}
/**
* 移动端微信支付
*/
public function actionMobilePay()
{
$weixinpay = \Yii::$app->params['weixinpay'];
$client = new Client(
[
'timeout' => 8,
'verify' => FALSE,
'connect_timeout' => 8
]
);
$order_id = '12312312323';
$uri = WeixinPay::UNIFIEDORDER;
$xml = [
'appid' => $weixinpay['appid'],
'mch_id' => $weixinpay['mchid'],
'device_info' => "WEB",
'nonce_str' => Yii::$app->security->generateRandomString(16),
'sign' => '',
'body' => '最课堂-课程购买',
'out_trade_no' => $order_id,
'total_fee' => 1,
'spbill_create_ip' => $_SERVER['SERVER_ADDR'],
'notify_url' => WeixinPay::NOTIFY_URL,
'trade_type' => 'MWEB',
];
$xml['sign'] = WeixinPay::makeWeixinPaySign($xml, $weixinpay['key']);
$xml = Utils::assocArrayToXML('xml', $xml);
$reponse = $client->request('POST', $uri, ['Content-Type' => 'text/xml; charset=UTF8', 'body' => $xml]);
$reponse = $reponse->getBody();
$result = ((string)$reponse);
$result = Utils::xmlToArray($result);
var_dump($result);
}
/**
* 生成订单号
* 格式 时间_uid_courseId
* @param $userId
* @param $courseId
* @param $price
* @return false|string
*/
private function generateOrderNumber($userId, $courseId, $price)
{
return md5(date("YmdHis", time()) . "_{$userId}_{$courseId}_{$price}");
}
} }
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/12
* Time: 下午4:05
*/
namespace frontend\controllers;
use common\libs\alipay\AlipayNotify;
use common\libs\Utils;
use common\libs\WeixinPay;
use common\models\Consume;
use common\models\Course;
use common\models\Income;
use common\models\Orders;
use dosamigos\qrcode\formats\Wifi;
use GuzzleHttp\Client;
use yii\log\Logger;
use yii\web\Controller;
class PayController extends Controller
{
public $enableCsrfValidation = FALSE;
public function actionAlipayNotify()
{
//计算得出通知验证结果
$alipayNotify = new AlipayNotify();
$verify_result = $alipayNotify->verifyNotify();
if ($verify_result) {//验证成功
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//请在这里加上商户的业务逻辑程序代
//——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
//获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
//商户订单号
$out_trade_no = $_POST['out_trade_no'];
$trade_no = $_POST['trade_no'];
$order = Orders::findOne(['number' => $out_trade_no]);
//交易状态
$trade_status = $_POST['trade_status'];
//并添加消费记录
$consume = new Consume();
$consume->orders_id = $order->id;
$consume->user_id = $order->user_id;
$consume->save();
//添加收入记录
$income = new Income();
$income->orders_id = $order->id;
$courseInfo = Course::findBaseInfoByCourseId($order->course_id);
$income->user_id = $courseInfo['user_id'];
$income->save();
if ($trade_status == 'TRADE_FINISHED' or $trade_status == 'TRADE_SUCCESS') {
$order->pay_order = $trade_no;
$order->status = Orders::PAID;
$order->update();
}
//——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
echo "success"; //请不要修改或删除
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
} else {
//验证失败
echo "fail";
//调试用,写文本函数记录程序运行情况是否正常
//logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
}
}
/**
* weixin支付回调接口
* @return object
*/
public function actionWeixinPayCallback()
{
//获取
$data = (\Yii::$app->request->post());
$weixinpay = \Yii::$app->params['weixinpay'];
$order_id = $data['product_id'];
//发送统一下单请求
$client = new Client(
[
'timeout' => 8,
'verify' => FALSE,
'connect_timeout' => 8
]
);
$uri = WeixinPay::UNIFIEDORDER;
$xml = [
'appid' => $weixinpay['appid'],
'mch_id' => $weixinpay['mchid'],
'device_info' => "WEB",
'nonce_str' => $data['nonce_str'],
'sign' => '',
'body' => '最课堂-课程购买',
'out_trade_no' => $order_id,
'total_fee' => 1,
'spbill_create_ip' => $_SERVER['SERVER_ADDR'],
'notify_url' => WeixinPay::NOTIFY_URL,
'trade_type' => 'NATIVE',
];
$xml['sign'] = WeixinPay::makeWeixinPaySign($xml, $weixinpay['key']);
$xml = Utils::assocArrayToXML('xml', $xml);
$reponse = $client->request('POST', $uri, ['Content-Type' => 'text/xml; charset=UTF8', 'body' => $xml]);
$reponse = $reponse->getBody();
$result = ((string)$reponse);
$result = Utils::xmlToArray($result);
$flag = TRUE;
if ($result['return_code'] !== 'SUCCESS') {
$flag = FALSE;
\Yii::getLogger()->log($result['return_msg'], Logger::LEVEL_ERROR);
} else if ($result['result_code'] !== 'SUCCESS') {
$flag = FALSE;
\Yii::getLogger()->log($result['err_code'] . ':' . $result['err_code_des'], Logger::LEVEL_ERROR);
}
if ($flag === FALSE) {
return \Yii::createObject([
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_XML,
'formatters' => [
\yii\web\Response::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
'rootTag' => 'xml', //根节点
],
],
'data' => $result
]);
}
if ($result['sign'] !== WeixinPay::makeWeixinPaySign($result, $weixinpay['key'])) {
return \Yii::createObject([
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_XML,
'formatters' => [
\yii\web\Response::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
'rootTag' => 'xml', //根节点
],
],
'data' => [
'return_code' => 'FAIL',
'return_msg' => '数据错误'
]
]);
}
$prepay_id = $result['prepay_id'];
$return = [
'return_code' => 'SUCCESS',
'appid' => $weixinpay['appid'],
'mch_id' => $weixinpay['mchid'],
'nonce_str' => $result['nonce_str'],
'prepay_id' => $prepay_id,
'result_code' => 'SUCCESS',
'sign' => ''
];
$return['sign'] = WeixinPay::makeWeixinPaySign($return, $weixinpay['key']);
//生成订单数据
return \Yii::createObject([
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_XML,
'formatters' => [
\yii\web\Response::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
'rootTag' => 'xml', //根节点
],
],
'data' => $return
]);
}
/**
* 微信notify_url
*/
public function actionWeixinNotify()
{
$data = (\Yii::$app->request->post());
$flag = TRUE;
if ($data['return_code'] !== 'SUCCESS') {
$flag = FALSE;
\Yii::getLogger()->log($data['return_msg'], Logger::LEVEL_ERROR);
} elseif ($data['result_code'] !== 'SUCCESS') {
$flag = FALSE;
\Yii::getLogger()->log($data['err_code'] . ':' . $data['err_code_des'], Logger::LEVEL_ERROR);
}
if ($flag === FALSE) {
return \Yii::createObject([
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_XML,
'formatters' => [
\yii\web\Response::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
'rootTag' => 'xml', //根节点
],
],
'data' => $data
]);
}
$weixinpay = \Yii::$app->params['weixinpay'];
if ($data['sign'] !== $weixinpay['key']) {
return \Yii::createObject([
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_XML,
'formatters' => [
\yii\web\Response::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
'rootTag' => 'xml', //根节点
],
],
'data' => [
'return_code' => 'FAIL',
'return_msg' => '数据错误'
]
]);
}
$orderId = $data['out_trade_no'];
$payOrder = $data['transaction_id'];
//修改订单状态
$order = Orders::findOne(['number' => $orderId]);
$order->status = Orders::PAID;
$order->pay_order = $payOrder;
$order->update();
//并添加消费记录
$consume = new Consume();
$consume->orders_id = $order->id;
$consume->user_id = $order->user_id;
$consume->save();
//添加收入记录
$income = new Income();
$income->orders_id = $order->id;
$courseInfo = Course::findBaseInfoByCourseId($order->course_id);
$income->user_id = $courseInfo['user_id'];
$income->save();
return \Yii::createObject([
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_XML,
'formatters' => [
\yii\web\Response::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
'rootTag' => 'xml', //根节点
],
],
'data' => [
'return_code' => 'SUCCESS',
'return_msg' => 'OK'
]
]);
}
}
opcache_invalidate(__FILE__);
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 上午9:57
*/
namespace frontend\controllers;
use common\libs\Utils;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use yii\log\Logger;
use yii\web\Controller;
class TestController extends Controller
{
public $enableCsrfValidation = FALSE;
public function actionIndex2()
{
$data = (\Yii::$app->request->post());
$order_id = date("YmdHis");
$order_id = '20161013135950';
//发送统一下单请求
$client = new Client(
[
'timeout' => 8,
'verify' => FALSE,
'connect_timeout' => 8
]
);
$uri = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
$weixinpay = \Yii::$app->params['weixinpay'];
$xml = [
'appid' => $weixinpay['appid'],
'mch_id' => $weixinpay['mchid'],
'device_info' => "WEB",
'nonce_str' => \Yii::$app->security->generateRandomString(16),
'sign' => '',
'body' => '云崖充值中心-课程购买',
'out_trade_no' => $order_id,
'total_fee' => 1,
'spbill_create_ip' => '114.112.65.4',
'notify_url' => 'http://c.pp.cc/frontend/web/index.php/pay/weixin-notify',
'trade_type' => 'NATIVE',
];
$xml['sign'] = Utils::makeWeixinPaySign($xml, $weixinpay['key']);
$xml = Utils::assocArrayToXML('xml', $xml);
$reponse = $client->request('POST', $uri, ['Content-Type' => 'text/xml; charset=UTF8', 'body' => $xml]);
$reponse = $reponse->getBody();
$result = ((string)$reponse);
$result = simplexml_load_string($result);
$prepay_id = (string)$result->prepay_id;
$return = [
'return_code' => 'SUCCESS',
'appid'=>$weixinpay['appid'],
'mch_id'=>$weixinpay['mchid'],
'nonce_str'=>(string)$result->nonce_str,
'prepay_id'=>(string)$result->prepay_id,
'result_code'=>'SUCCESS',
'sign'=>''
];
$return['sign'] = Utils::makeWeixinPaySign($return,$weixinpay['key']);
return \Yii::createObject([
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_XML,
'formatters' => [
\yii\web\Response::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
'rootTag' => 'xml', //根节点
],
],
'data' => $return
]);
// var_dump(Yii::$app->request->post());
// $log = \Yii::$app->log->getLogger();
// $log->log(json_encode($data),Logger::LEVEL_ERROR);
}
public function actionIndex(){
return $this->render('index');
}
}
opcache_invalidate(__FILE__);
\ No newline at end of file
...@@ -125,7 +125,6 @@ class UserCenterController extends Controller ...@@ -125,7 +125,6 @@ class UserCenterController extends Controller
if ($user->avatar !== $avatar) { if ($user->avatar !== $avatar) {
$oldAvatar = $user->avatar; $oldAvatar = $user->avatar;
} }
}
$user->avatar = Html::encode($avatar); $user->avatar = Html::encode($avatar);
$user->username = Html::encode($username); $user->username = Html::encode($username);
$user->save(); $user->save();
...@@ -136,6 +135,8 @@ class UserCenterController extends Controller ...@@ -136,6 +135,8 @@ class UserCenterController extends Controller
//认领资源 //认领资源
UploadPools::claimFileBySkey(UploadPools::getSkey('public', $avatar)); UploadPools::claimFileBySkey(UploadPools::getSkey('public', $avatar));
} }
}
Utils::ajaxResponse($status, $msg); Utils::ajaxResponse($status, $msg);
} else { } else {
throw new \yii\web\ForbiddenHttpException('非法请求'); throw new \yii\web\ForbiddenHttpException('非法请求');
......
...@@ -2,24 +2,13 @@ ...@@ -2,24 +2,13 @@
/* @var $this yii\web\View */ /* @var $this yii\web\View */
\frontend\assets\AppAsset::addScript($this, '@web/assets/home_index.js'); \frontend\assets\AppAsset::addScript($this, '@web/assets/home_index.js');
\frontend\assets\AppAsset::addCss($this, '@web/assets/css/home_index.css'); \frontend\assets\AppAsset::addCss($this, '@web/assets/css/home_index.css');
\frontend\assets\AppAsset::addCss($this, '@web/assets/css/main.css');
?> ?>
<h1>home/index</h1> <input id="class-info" type="hidden" value="<?= \yii\helpers\Html::encode(json_encode($classInfo)) ?>"/>
<p>
<video id="example_video_1" class="video-js vjs-default-skin vjs-big-play-centered"
controls preload="auto" width="640" height="264"
poster="http://dev.qdn.pp.cc/object/test-thumb1.jpg"
data-setup='{"example_option":true,"autoplay":false,"language":"zh-CN"}'>
<source src="http://dev.qdn.pp.cc/object/test-3.mp4" type="video/mp4"/>
</video> <div id="index-container">
</p> <recommend :class-id="classId"></recommend>
<course-lists :class-id="classId"></course-lists>
</div>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/14
* Time: 下午5:39
*/
$this->title = "视频播放";
\frontend\assets\AppAsset::addCss($this, '@web/assets/css/main.css');
\frontend\assets\AppAsset::addScript($this, '@web/assets/home_video.js');
\frontend\assets\AppAsset::addCss($this, '@web/assets/css/home_video.css');
?>
<div class="container">
<div class="cnt-tit">
<h3>为什么身体会做出不由自主的行为?</h3>
<div class="tit-share hidden-xs">
<a href="javascript:;" class="wechat post-icons"></a>
<a href="javascript:;" class="weibo post-icons"></a>
<a href="javascript:;" class="qzone post-icons"></a>
</div>
</div>
<div class="video-main">
<video id="example_video_1" class="video-js vjs-default-skin vjs-big-play-centered"
controls preload="auto" width="1280" height="264"
poster="<?= \yii\helpers\Html::encode($coursewareInfo['previewUrl']) ?>"
data-setup='{"example_option":true,"autoplay":false,"language":"zh-CN"}'>
<source src="<?= \yii\helpers\Html::encode($coursewareInfo['videoUrl']) ?>" type="video/mp4"/>
</video>
</div>
<div class="video-detail-info">
<div class="video-teacher">
<a href="#"><img src="img/avatar2.jpg"></a>
<p><a href="#">乔布斯</a></p>
<span>2016-10-08</span>
</div>
<div class="video-sm-info">
<a href="#"><i class="icon-comment-empty"></i>543</a>
<a href="#"><i class="icon-fav-empty"></i>31</a>
<a href="#"><i class="icon-zan-empty"></i>97</a>
</div>
</div>
</div>
<!--视频介绍-->
<div class="warp-box">
<div class="container">
<div class="video-description">
<div class="title">视频介绍</div>
<div class="text">
<?= \yii\helpers\Html::encode($coursewareInfo['intro'])?>
</div>
</div>
<div class="video-comment">
<div class="title">评论
<small>607次</small>
</div>
</div>
<?php if(Yii::$app->user->isGuest):?>
<div class="comment-login">
需要 <a href="#">登录</a> 才能评论
</div>
<?php endif;?>
<div class="comment-box">
<div class="comment-head">
<img src="img/avatar2.jpg">
</div>
<div class="comment-input clearfix">
<textarea name="" id="" cols="30" rows="10" class="form-control" placeholder="说几句吧,亲..."></textarea>
<button class="btn btn-default pull-right m-t-10">发表评论</button>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatar2.jpg"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatar2.jpg"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatarMax.png"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatar2.jpg"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatarMax.png"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
</div>
</div>
...@@ -16,7 +16,7 @@ $baseUrl = \yii\helpers\Url::base(); ...@@ -16,7 +16,7 @@ $baseUrl = \yii\helpers\Url::base();
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<html lang="<?= Yii::$app->language ?>"> <html lang="<?= Yii::$app->language ?>">
<title><?=$this->title?></title> <title><?= $this->title ?></title>
<meta charset="<?= Yii::$app->charset ?>"> <meta charset="<?= Yii::$app->charset ?>">
<meta name="description" content=""> <meta name="description" content="">
<meta name="keywords" content=""> <meta name="keywords" content="">
...@@ -45,10 +45,7 @@ $baseUrl = \yii\helpers\Url::base(); ...@@ -45,10 +45,7 @@ $baseUrl = \yii\helpers\Url::base();
</nav> </nav>
<div class="container"> <?= $content ?>
<?= $content ?>
</div>
<?php $this->endBody() ?> <?php $this->endBody() ?>
......
<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
<h1><?= Html::encode($this->title) ?></h1>
<p>This is the About page. You may modify the following file to customize its content:</p>
<code><?= __FILE__ ?></code>
</div>
<?php
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\ContactForm */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
$this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
<h1><?= Html::encode($this->title) ?></h1>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
...@@ -9,7 +9,8 @@ use yii\helpers\Html; ...@@ -9,7 +9,8 @@ use yii\helpers\Html;
$this->title = $name; $this->title = $name;
?> ?>
<div class="site-error"> <div class="container">
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
...@@ -24,4 +25,5 @@ $this->title = $name; ...@@ -24,4 +25,5 @@ $this->title = $name;
Please contact us if you think this is a server error. Thank you. Please contact us if you think this is a server error. Thank you.
</p> </p>
</div>
</div> </div>
...@@ -7,7 +7,8 @@ use yii\widgets\ActiveForm; ...@@ -7,7 +7,8 @@ use yii\widgets\ActiveForm;
$this->title = '登录'; $this->title = '登录';
$baseUrl = \yii\helpers\Url::base(); $baseUrl = \yii\helpers\Url::base();
?> ?>
<div class="z-m-center"> <div class="container">
<div class="z-m-center">
<h3>云涯</h3> <h3>云涯</h3>
<p>欢迎来到最课堂,专注在线直播</p> <p>欢迎来到最课堂,专注在线直播</p>
...@@ -62,4 +63,5 @@ $baseUrl = \yii\helpers\Url::base(); ...@@ -62,4 +63,5 @@ $baseUrl = \yii\helpers\Url::base();
</div> </div>
</div>
</div> </div>
...@@ -11,7 +11,8 @@ $this->title = '找回密码'; ...@@ -11,7 +11,8 @@ $this->title = '找回密码';
$this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
?> ?>
<div class="z-m-center"> <div class="container">
<div class="z-m-center">
<h3>找回密码</h3> <h3>找回密码</h3>
<p>请按步骤获取密码</p> <p>请按步骤获取密码</p>
...@@ -53,5 +54,6 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); ...@@ -53,5 +54,6 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
</div> </div>
</div>
</div> </div>
...@@ -21,7 +21,8 @@ JS; ...@@ -21,7 +21,8 @@ JS;
$this->registerJs($jsString); $this->registerJs($jsString);
?> ?>
<div class="z-m-center"> <div class="container">
<div class="z-m-center">
<h3>找回密码</h3> <h3>找回密码</h3>
<p>请按步骤获取密码</p> <p>请按步骤获取密码</p>
...@@ -59,5 +60,6 @@ $this->registerJs($jsString); ...@@ -59,5 +60,6 @@ $this->registerJs($jsString);
</div> </div>
</div>
</div> </div>
...@@ -12,7 +12,8 @@ $this->title = '密码设置成功'; ...@@ -12,7 +12,8 @@ $this->title = '密码设置成功';
?> ?>
<div class="z-m-center"> <div class="container">
<div class="z-m-center">
<h3>找回密码</h3> <h3>找回密码</h3>
<p>请按步骤获取密码</p> <p>请按步骤获取密码</p>
...@@ -45,5 +46,6 @@ $this->title = '密码设置成功'; ...@@ -45,5 +46,6 @@ $this->title = '密码设置成功';
</div> </div>
</div>
</div> </div>
...@@ -10,7 +10,8 @@ $baseUrl = \yii\helpers\Url::base(); ...@@ -10,7 +10,8 @@ $baseUrl = \yii\helpers\Url::base();
$this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
?> ?>
<div class="z-m-center"> <div class="container">
<div class="z-m-center">
<h3>云涯</h3> <h3>云涯</h3>
<p>欢迎来到最课堂,专注在线直播</p> <p>欢迎来到最课堂,专注在线直播</p>
...@@ -71,4 +72,5 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); ...@@ -71,4 +72,5 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
</div> </div>
</div>
</div> </div>
...@@ -15,7 +15,8 @@ $this->title = '输入验证码'; ...@@ -15,7 +15,8 @@ $this->title = '输入验证码';
$this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
?> ?>
<div class="z-m-center"> <div class="container">
<div class="z-m-center">
<h3>找回密码</h3> <h3>找回密码</h3>
<p>请按步骤获取密码</p> <p>请按步骤获取密码</p>
...@@ -55,4 +56,5 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); ...@@ -55,4 +56,5 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
</div> </div>
</div>
</div> </div>
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 下午5:32
*/
use yii\helpers\Url;
?>
<img src="<?= Url::to(['home/weixin-pay-qrcode'])?>" />
This diff is collapsed.
...@@ -21,10 +21,7 @@ a,a:hover,a:link { ...@@ -21,10 +21,7 @@ a,a:hover,a:link {
.yun-login-btn li a { .yun-login-btn li a {
color: #333; color: #333;
} }
.yun-login-btn li:last-child a{
background-color: #34bf49;
color: #fff;
}
.z-m-center { .z-m-center {
......
@charset "utf-8";
body {
font-family: "Microsoft YaHei","Helvitica Neue", Helvitica, Arial, "Hiragino Sans GB", "Arial Regular", "Microsoft JhengHei", sans-serif;
background-color: #fafafa;
}
a,a:hover,a:link {
text-decoration: none;
}
/*font*/
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?uyryw3');
src: url('fonts/icomoon.eot?uyryw3#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?uyryw3') format('truetype'),
url('fonts/icomoon.woff?uyryw3') format('woff'),
url('fonts/icomoon.svg?uyryw3#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="icon-"], [class*=" icon-"] {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'icomoon' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-comment-empty:before {
content: "\e900";
}
.icon-comment-full:before {
content: "\e901";
}
.icon-fav-empty:before {
content: "\e902";
}
.icon-fav-full:before {
content: "\e903";
}
.icon-zan-empty:before {
content: "\e904";
}
.icon-zan-full:before {
content: "\e905";
}
.navbar-main {
background-color: #fff;
box-shadow: 0 0 30px rgba(0,0,0,.05);
}
.logo {
line-height: 60px;
margin-left: 30px;
font-size: 16px;
}
.logo a {
color: #333;
}
.yun-login-btn {
margin-right: 30px;
margin-bottom: 0;
}
.yun-login-btn,.yun-login-btn li {
list-style: none;
}
.yun-login-btn li {
display: inline-block;
height: 60px;
line-height: 60px;
padding: 0 10px;
}
.yun-login-btn li a {
color: #333;
display: block;
}
.c-menu-item {
margin-bottom: 0;
margin-left: 20px;
}
.c-menu-item li {
display: inline-block;
height: 60px;
line-height: 60px;
margin: 0 10px 0;
padding: 0;
}
.c-menu-item li a {
display: block;
height: 60px;
color: #333;
}
.c-menu-item li.active a {
display: block;
border-bottom: 4px solid #ef2f11;
}
/* Swiper幻灯 */
.swiper-container {
width: 100%;
height: 500px;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
/*视频列表*/
.v-list {
margin-top: 20px;
}
.v-main-box {
background-color: #fff;
height: 300px;
margin-bottom: 20px;
-webkit-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.v-screen {
position: relative;
width: 100%;
height: 200px;
overflow: hidden;
}
.v-screen a {
position: relative;
display: block;
}
.v-screen > span {
position: absolute;
display: inline-block;
width: 30px;
height: 30px;
left: 10px;
top:10px;
}
.v-screen > span > img {
width: 30px;
height: 30px;
border-radius: 100%;
}
.v-tit,
.v-price,
.v-foot {
padding: 0 10px;
}
.v-tit {
height: 40px;
line-height: 40px;
font-size: 14px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.v-tit a {
color: #333333;
}
.v-price {
color: #ef2f11;
padding-bottom: 10px;
}
.v-foot {
position: relative;
font-size: 12px;
color: #999;
}
.v-detail {
position: absolute;
right: 10px;
bottom: 0;
color: #bbbbbb;
}
.v-detail span {
padding-left: 10px;
}
.v-main-box:hover {
cursor: pointer;
box-shadow: 0 0 20px rgba(0,0,0,.12);
}
.v-main-box:hover .play-mask {
display: inline-block;
line-height: 200px;
}
.play-mask {
display: none;
position: absolute;
background-color: rgba(0,0,0,.3);
width: 100%;
height: 200px;
left: 0;
top: 0;
text-align: center;
line-height: 200px;
font-size: 64px;
color: #fff;
-webkit-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.col-md-3 {
padding-right: 10px;
padding-left: 10px;
}
.get-more {
margin: 0 auto;
width: 30%;
text-align: center;
font-size: 12px;
}
.get-more a {
display: block;
height: 45px;
line-height: 45px;
background-color: #fff;
color: #999;
}
.copyright {
height: 40px;
line-height: 40px;
background-color: #fff;
text-align: center;
color: #999;
font-size: 12px;
border-top: 1px solid #f3f3f3;
}
.m-t-20 {
margin-top: 20px;
}
/*视频内容页面*/
.cnt-tit {
position: relative;
height: 22px;
font-size: 22px;
margin: 30px 0;
}
.tit-share {
position: absolute;
display: inline-block;
height: 22px;
right: 0;
top: 0;
}
.post-icons {
width: 25px;
height: 22px;
float: left;
margin-left: 16px;
background: url(../img/share_tit.png) no-repeat;
}
.weibo {
background-position: -25px 0;
}
.qzone {
background-position: -50px 0;
}
.weibo:hover {
background-position: -25px -22px;
}
.qzone:hover {
background-position: -50px -22px;
}
.wechat:hover {
background-position: 0 -22px;
}
.video-detail-info {
position: relative;
height: 80px;
background-color: #fff;
border: 1px solid #f3f3f3;
border-top: none;
}
.video-teacher {
padding: 15px;
}
.video-teacher a {
color: #333;
}
.video-teacher img{
float: left;
width: 50px;
height: 50px;
border-radius: 100%;
margin-right: 10px;
}
.video-teacher p {
font-size: 16px;
margin: 5px 0 0;
}
.video-teacher span {
font-size: 12px;
color: #999;
}
.video-sm-info {
position: absolute;
height: 80px;
line-height: 80px;
right: 15px;
top: 0;
}
.video-sm-info a {
display: inline-block;
position: relative;
margin-right: 15px;
vertical-align: middle;
font-size: 12px;
color: #999;
padding-left: 35px;
height: 30px;
line-height: 30px;
}
.video-sm-info a i {
position: absolute;
width: 30px;
height: 30px;
text-align: center;
line-height: 30px;
top: 0;
left: 0;
font-size: 30px;
}
/*video detail*/
.warp-box {
background-color: #fff;
margin-top: 40px;
padding: 20px 0;
border-top: 1px solid #f3f3f3;
}
.video-description .title {
font-size: 16px;
color: #333;
padding-bottom: 10px;
}
.video-description .text {
color: #999;
}
.video-comment {
margin-top: 30px;
}
.video-comment .title {
font-size: 16px;
color: #333;
padding-bottom: 10px;
}
.video-comment .title small {
font-size: 12px;
color: #999;
padding-left: 10px;
}
.comment-login {
display: block;
width: 100%;
height: 100px;
text-align: center;
line-height: 100px;
border: 1px solid #e5e6e8;
}
.comment-box {
position: relative;
padding-left: 60px;
margin-top: 20px;
}
.comment-head img {
width: 50px;
height: 50px;
border-radius: 100%;
}
.comment-head {
position: absolute;
left: 0;
top: 0;
padding-right: 10px;
}
.comment-input {
display: block;
}
.comment-input textarea {
height: 50px;
}
.m-t-10 {
margin-top: 10px;
}
.user-h {
padding-right: 10px;
}
.user-h img {
height: 50px;
width: 50px;
border-radius: 100%;
}
.user-i span,
.user-i span small {
font-size: 14px;
color: #999;
}
.user-i span small {
padding-left: 5px;
}
.user-i p {
padding-top: 5px;
}
.comment-main-list {
margin-bottom: 40px;
}
.teacher-info {
margin: 40px auto;
}
.teacher-info img {
width: 100px;
height: 100px;
border-radius: 100%;
}
.teacher-info h3 {
font-size: 18px;
}
.teacher-info p {
max-width: 500px;
margin: 0 auto;
color: #666;
}
\ No newline at end of file
...@@ -181,6 +181,7 @@ ul, ...@@ -181,6 +181,7 @@ ul,
ol, ol,
li { li {
list-style: none; list-style: none;
float: left;
} }
i, em { i, em {
...@@ -231,6 +232,24 @@ i, em { ...@@ -231,6 +232,24 @@ i, em {
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
.icon-comment-empty:before {
content: "\e900";
}
.icon-comment-full:before {
content: "\e901";
}
.icon-fav-empty:before {
content: "\e902";
}
.icon-fav-full:before {
content: "\e903";
}
.icon-zan-empty:before {
content: "\e904";
}
.icon-zan-full:before {
content: "\e905";
}
.icon-add:before { .icon-add:before {
content: "\e145"; content: "\e145";
} }
...@@ -273,12 +292,21 @@ i, em { ...@@ -273,12 +292,21 @@ i, em {
.icon-crop_original:before { .icon-crop_original:before {
content: "\e3c4"; content: "\e3c4";
} }
.icon-favorite:before {
content: "\e87d";
}
.icon-favorite_border:before {
content: "\e87e";
}
.icon-fingerprint:before { .icon-fingerprint:before {
content: "\e90d"; content: "\e90d";
} }
.icon-ondemand_video:before { .icon-ondemand_video:before {
content: "\e63a"; content: "\e63a";
} }
.icon-power_settings_new:before {
content: "\e8ac";
}
.icon-slideshow:before { .icon-slideshow:before {
content: "\e41b"; content: "\e41b";
} }
...@@ -390,4 +418,3 @@ i, em { ...@@ -390,4 +418,3 @@ i, em {
.icon-menu:before { .icon-menu:before {
content: "\e120"; content: "\e120";
} }
<template>
<div class="container v-list" v-show="lists.length > 0">
<div class="row">
<div v-for="item in lists" class="col-md-3">
<div class="v-main-box">
<div class="v-screen">
<a @click="itemClick(item.id)" href="javascript:;">
<img :src="getFullPreViewPic(item.preview_pic)">
<span class="play-mask"><i class="glyphicon glyphicon-play-circle"></i></span>
</a>
<!--头像-->
<span><img src="http://dev.zuiketang.com/assets/img/avatar2.jpg"></span>
</div>
<div class="v-tit"><a @click="itemClick(item.id)" href="javascript:;">{{item.name}}</a></div>
<div class="v-price">
<small>¥</small>
{{item.price}}
</div>
<div class="v-foot">
<p>{{transcateTime(item.created_at)}}</p>
<!--<div class="v-detail">-->
<!--<span><i class="icon-comment-full"></i> 12031</span>-->
<!--<span><i class="icon-fav-full"></i> 87</span>-->
<!--<span><i class="icon-zan-full"></i> 331</span>-->
<!--</div>-->
</div>
</div>
</div>
</div>
<div @click="moreClick" v-show="more" class="get-more"><a href="javascript:;">点击查看更多</a></div>
</div>
</template>
<script>
import moment from 'moment';
export default{
data(){
return {
lists: [],
page: 0,
num: 10,
more: false
}
},
methods: {
itemClick(id)
{
window.location.href = __BASE_URL__ + 'home/video?courseId=' + id;
},
transcateTime(time)
{
return moment(new Date(time * 1000)).format('YYYY-MM-DD HH:mm:ss');
}
,
getFullPreViewPic(pic)
{
return __QINIU_URL__ + '/' + pic;
}
,
moreClick()
{
this.page++;
this.getLists(this.classId, this.page, this.num);
}
,
getLists(classId, page, num)
{
var url = __BASE_URL__ + 'home/get-course-lists?classId=' + classId + '&page=' +
page + '&num=' + num;
var self = this;
$.getJSON(url, function (reponse) {
if (reponse.status === true) {
var result = reponse.data;
self.count = result.count;
self.lists = self.lists.concat(result.data);
self.more = (self.count > self.lists.length);
} else {
layer.alert(reponse.message, {'icon': 2, 'title': '提示'})
}
}).error(function () {
layer.alert('获取推荐课堂列表错误', {'icon': 2, 'title': '提示'})
})
}
},
props: {
classId: {
required: true
}
}
,
ready()
{
this.getLists(this.classId, this.page, this.num);
}
}
</script>
<template>
<div class="swiper-container" v-if="lists.length !== 0">
<div class="swiper-wrapper">
<div v-for="item in lists" @click="itemClick(item.id)" class="swiper-slide"
:style="{background: 'url('+getFullPreViewPic(item.preview_pic)+') top center no-repeat'}">
{{item.name}}
</div>
</div>
<div class="swiper-pagination"></div>
</div>
</template>
<script>
require('../../libs/swiper/swiper.min.css');
var Swiper = require('../../libs/swiper/swiper.min.js');
export default{
data(){
return {
lists: []
}
},
props: {
classId: {
required: true
}
},
watch: {
lists(){
this.$nextTick(function () {
new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
paginationClickable: true,
spaceBetween: 30,
centeredSlides: true,
autoplay: 2500,
autoplayDisableOnInteraction: false
});
});
}
},
methods: {
itemClick(id){
window.location.href = __BASE_URL__ + 'home/video?courseId=' + id;
},
getFullPreViewPic(pic){
return __QINIU_URL__ + '/' + pic;
},
getLists(classId){
var url = __BASE_URL__ + 'home/get-recommend-courses?classId=' + classId;
var self = this;
$.getJSON(url, function (reponse) {
if (reponse.status === true) {
self.lists = reponse.data;
} else {
layer.alert(reponse.message, {'icon': 2, 'title': '提示'})
}
}).error(function () {
layer.alert('获取推荐课堂列表错误', {'icon': 2, 'title': '提示'})
})
}
},
components: {},
ready()
{
this.getLists(this.classId);
}
}
</script>
/** /**
* Created by xiabin on 2016/9/29. * Created by xiabin on 2016/9/29.
*/ */
require('expose?videojs!../libs/videojs/video.js'); // require('expose?videojs!../libs/videojs/video.js');
require('../libs/videojs/video-js.css'); // require('../libs/videojs/video-js.css');
require('../libs/videojs/lang/zh-CN.js'); // require('../libs/videojs/lang/zh-CN.js');
// console.log(videojs); // // console.log(videojs);
// layer.msg('home/index'); // // layer.msg('home/index');
videojs.options.flash.swf = __CDN_URL__ + 'assets/videojs/video-js.swf'; // videojs.options.flash.swf = __CDN_URL__ + 'assets/videojs/video-js.swf';
window.VIDEOJS_NO_BASE_THEME = true; // window.VIDEOJS_NO_BASE_THEME = true;
//
// videojs("example_video_1").ready(function () {
// var myPlayer = this;
//
// // EXAMPLE: Start playing the video.
// // myPlayer.play();
//
// });
var Vue = require('vue');
var recommend = require('./components/recommend.vue');
var courseLists = require('./components/course-lists.vue');
var classInfo = JSON.parse($('#class-info').val());
videojs("example_video_1").ready(function () {
var myPlayer = this;
// EXAMPLE: Start playing the video. new Vue({
myPlayer.play(); el: "#index-container",
data: {
classId: classInfo.id
},
components: {
recommend: recommend,
courseLists: courseLists
}
}); });
/**
* Created by xiabin on 2016/10/14.
*/
require('expose?videojs!../libs/videojs/video.js');
require('../libs/videojs/video-js.css');
require('../libs/videojs/lang/zh-CN.js');
// console.log(videojs);
// layer.msg('home/index');
videojs.options.flash.swf = __CDN_URL__ + 'assets/videojs/video-js.swf';
window.VIDEOJS_NO_BASE_THEME = true;
//
videojs("example_video_1").ready(function () {
var myPlayer = this;
// EXAMPLE: Start playing the video.
// myPlayer.play();
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -12,6 +12,7 @@ var entry = { ...@@ -12,6 +12,7 @@ var entry = {
vendor: ["jquery", "vue", js_dir + "/utils/layer", js_dir + "/libs/global.js"], vendor: ["jquery", "vue", js_dir + "/utils/layer", js_dir + "/libs/global.js"],
login_css: [css_dir + '/login.css'], login_css: [css_dir + '/login.css'],
style: [css_dir + '/reset.css', css_dir + '/style.css'], style: [css_dir + '/reset.css', css_dir + '/style.css'],
main: [css_dir + '/main.css'],
signup: [js_dir + '/site/signup.js'], signup: [js_dir + '/site/signup.js'],
login: [js_dir + '/site/login.js'], login: [js_dir + '/site/login.js'],
request_password_reset: [js_dir + '/site/request_password_reset'], request_password_reset: [js_dir + '/site/request_password_reset'],
...@@ -21,6 +22,7 @@ var entry = { ...@@ -21,6 +22,7 @@ var entry = {
user_center_browse_record: [js_dir + '/user-center/browse_record.js'], user_center_browse_record: [js_dir + '/user-center/browse_record.js'],
user_center_purchased_course: [js_dir + '/user-center/purchased_course.js'], user_center_purchased_course: [js_dir + '/user-center/purchased_course.js'],
home_index: [js_dir + '/home/index.js'], home_index: [js_dir + '/home/index.js'],
home_video: [js_dir + '/home/video.js'],
course_publish: [js_dir + '/my-course/publish.js'], course_publish: [js_dir + '/my-course/publish.js'],
teacher_form: [js_dir + '/teacher-manager/form.js'] teacher_form: [js_dir + '/teacher-manager/form.js']
}; };
......
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/10/13
* Time: 上午10:38
*/
var_dump(function_exists('fnmatch'));
\ No newline at end of file
...@@ -129,8 +129,6 @@ ...@@ -129,8 +129,6 @@
<div class="copyright">© 2016 c.pp.cc 皖ICP备13046642号</div> <div class="copyright">© 2016 c.pp.cc 皖ICP备13046642号</div>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type='text/javascript' src="js/bootstrap.min.js"></script> <script type='text/javascript' src="js/bootstrap.min.js"></script>
<script type='text/javascript' src="js/swiper.min.js"></script> <script type='text/javascript' src="js/swiper.min.js"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment