微信刷脸支付额外说明(青蛙设备)
后台只做两个交互
1、获取凭证
1-1、在官方demo里配置好appid、mchid、key即可
1-2、前端返回的rawdata要做处理,先去掉rawdata=,再用rawurldecode转义一下,否则获取authinfo失败
2、完成支付(支付要由后台做)
后台只做两个交互
1、获取凭证
1-1、在官方demo里配置好appid、mchid、key即可
1-2、前端返回的rawdata要做处理,先去掉rawdata=,再用rawurldecode转义一下,否则获取authinfo失败
2、完成支付(支付要由后台做)
压缩某个文件或多个文件
//这里需要注意该目录是否存在,并且有创建的权限
$zip_path = ROOT_PATH . 'public' . DS . 'uploads/zip';
if (!file_exists($zip_path)) {
mkdir($zip_path);
}
$zipname = $zip_path . '/exportdevice_' . date('Y-m-d-H-i-s') . '.zip';
$zip = new \ZipArchive();
$res = $zip->open($zipname, \ZipArchive::CREATE);
$img = ROOT_PATH . 'public' . DS . 'uploads/images/aaa.png';
if ($res === TRUE) {
$zip->addFile($img, basename($img)); //1、单个文件
foreach($fileList as $file){ //2、多个文件
$zip->addFile($file,basename($file));
}
}
$zip->close();
//这里是下载zip文件
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Length: " . filesize($zipname));
header("Content-Disposition: attachment; filename=\"" . basename($zipname) . "\"");
readfile($zipname);
exit;
}压缩某个文件夹
function addFileToZip($path,$zip){
$handler=opendir($path); //打开当前文件夹由$path指定。
while(($filename=readdir($handler))!==false){
if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
if(is_dir($path."/".$filename)){// 如果读取的某个对象是文件夹,则递归
addFileToZip($path."/".$filename, $zip);
}else{ //将文件加入zip对象
$zip->addFile($path."/".$filename);
}
}
}
@closedir($path);
}
$zip=new ZipArchive();
if($zip->open('rsa.zip', ZipArchive::OVERWRITE)=== TRUE){
addFileToZip('rsa/', $zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
$zip->close(); //关闭处理的zip文件
} PHP必须是7.2非debug版本
1、将一个swoole_loader_20_php72.so的文件放入/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718
2、在php配置文件最后面增加一行 extension=swoole_loader_20_php72.so
3、重启php-fpm
4、启用proc_open和proc_get_status函数(在php.ini里找到disable_functions,把这俩去掉,重启PHP)
5、别忘Linux运行:chmod a+x /data/wwwroot/shop.xiangshaokeji.com/queue.sh && /data/wwwroot/shop.xiangshaokeji.com/queue.sh
前端
$('#weibologin').click(function(){
location.href = 'https://api.weibo.com/oauth2/authorize?client_id=1228667031&response_type=code&redirect_uri=http://new3.xuanwumobile.com/html/login_win.html';
});
var Request = new UrlSearch(); //实例化
if(Request.code){
$.ajax({
url:'http://cloud.xuanwumobile.com/api/Timer/aaaaaa',
data:'code='+Request.code,
type:'post',
cache:false,
dataType:'json',
success:function(ret) {
if(ret.error){
tanKuang('授权出错!');
return;
}else{
var wbtoken = ret.uid;
alert(wbtoken)
}
},
error : function(err) {
alert(err);
}
});
}
function UrlSearch() {
var name, value;
var str = location.href; //取得整个地址栏
var num = str.indexOf("?")
str = str.substr(num + 1); //取得所有参数 stringvar.substr(start [, length ]
var arr = str.split("&"); //各个参数放到数组里
for (var i = 0; i < arr.length; i++) {
num = arr[i].indexOf("=");
if (num > 0) {
name = arr[i].substring(0, num);
value = arr[i].substr(num + 1);
this[name] = value;
}
}
}后端
header("Access-Control-Allow-Origin: *");
$code = $_REQUEST['code'];
$body_json = array( //不能用,得把参数放到url里,方法是post,但form-data是空,否则报错:miss client id or secret
'client_id' => '1228667031',
'client_secret' => '2363c310edc1c847fa80a4feedcb211b',
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => 'http://new3.xuanwumobile.com/html/login_win.html'
);
$body = json_encode($body_json);
$header = array(
'Accept:application/json',
'Content-Type:application/json;charset=utf-8',
);
//$url = 'https://api.weibo.com/oauth2/access_token';
$url = 'https://api.weibo.com/oauth2/access_token?client_id=1228667031&client_secret=XXXXXXXXXXXX&grant_type=authorization_code&redirect_uri=http://new3.xuanwumobile.com/html/login_win.html&code=' . $code;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, false);//formdata为false(即以前的$body_json )
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
curl_close($ch);
$res = json_decode($result, true);
return json($res);