PHP腾讯AI人脸融合

  • 2,193

缺点价格相当贵
带有天天p图水印

PHP腾讯AI人脸融合

<?php
header("Content-Type: text/html;charset=UTF-8");

// 图片base64编码
$path   = 'https://yyb.gtimg.com/aiplat/ai/upload/demo/large/facemerge-demo3.jpg';
$data   = file_get_contents($path);
$base64 = base64_encode($data);

// 设置请求数据
$appkey = '******';
$params = array(
    'app_id'     => '******',
    'image'      => $base64,
    'model'      => '5',
    'time_stamp' => strval(time()),
    'nonce_str'  => strval(rand()),
    'sign'       => '',
);
$params['sign'] = getReqSign($params, $appkey);

// 执行API调用
$url = 'https://api.ai.qq.com/fcgi-bin/ptu/ptu_facemerge';
$response = doHttpPost($url, $params);
$img = json_decode($response,true);
if($img['ret']!='4096'){

            $img = "<img src='data:image/jpg;base64,".$img['data']['image']."'/>'";
            // $img = base64_decode($img);
            echo $img;
        }


//   - 签名结果
function getReqSign($params /* 关联数组 */, $appkey /* 字符串*/)
{
    // 1. 字典升序排序
    ksort($params);

    // 2. 拼按URL键值对
    $str = '';
    foreach ($params as $key => $value)
    {
        if ($value !== '')
        {
            $str .= $key . '=' . urlencode($value) . '&';
        }
    }

    // 3. 拼接app_key
    $str .= 'app_key=' . $appkey;

    // 4. MD5运算+转换大写,得到请求签名
    $sign = strtoupper(md5($str));
    return $sign;
}
function doHttpPost($url, $params)
{
    $curl = curl_init();

    $response = false;
    do
    {
        // 1. 设置HTTP URL (API地址)
        curl_setopt($curl, CURLOPT_URL, $url);

        // 2. 设置HTTP HEADER (表单POST)
        $head = array(
            'Content-Type: application/x-www-form-urlencoded'
        );
        curl_setopt($curl, CURLOPT_HTTPHEADER, $head);

        // 3. 设置HTTP BODY (URL键值对)
        $body = http_build_query($params);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $body);

        // 4. 调用API,获取响应结果
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_NOBODY, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        $response = curl_exec($curl);
        if ($response === false)
        {
            $response = false;
            break;
        }

        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        if ($code != 200)
        {
            $response = false;
            break;
        }
    } while (0);

    curl_close($curl);
    return $response;
}



?>
weinxin
我的微信
这是我的微信扫一扫
开拓者博主
  • 本文由 发表于 2018年10月13日20:22:26
  • 转载请务必保留本文链接:https://www.150643.com/524.html
匿名

发表评论

匿名网友 填写信息

评论:1   其中:访客  1   博主  0
    • oye oye 3

      买单号 买快递单号 买空包 找空包代发选爱查www.aickd.com