<?php
/**
* 名称:QQ运动接口
* 出处:https://www.yowal.cn/
* 方式:POST
* 参数:openid,access_token,steps
* 时间:2019年10月25日
*/
error_reporting(0);
date_default_timezone_set('PRC');
//define('IN_CRONLITE', true);
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');

function getKey($str) {
    $string = $str."qlDFDfnbma!@23DKEd[";
    $bytes = array();
    for ($i = 0; $i < strlen($string); $i++) {
        $bytes[] = ord($string[$i]);
    }
    $arr = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
    $arr2 = [];
    $i2 = 0;
    foreach($bytes as $ch) {
        $arr2[($i2 * 2) + 1] = $arr[($ch >> 4) & 15];
        $arr2[($i2 * 2) + 0] = $arr[$ch & 15];
        $i2++;
    }
    return implode("",$arr2);
}

function request_post($url, $post_data) {
    $ch = curl_init();
    //初始化curl
    curl_setopt($ch, CURLOPT_URL,$url);
    //抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //设置header
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_POST, 1);
    //post提交方式
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $data = curl_exec($ch);
    //运行curl
    curl_close($ch);
    return $data;
}


$time = date("H",time());
if ($time <= 6 || $time >= 24) {
    $arr = array('ret' => -1,'msg' => 'QQ运动刷步失败!原因:当前时间段禁止刷步');
    $json_string = json_encode($arr,JSON_UNESCAPED_UNICODE);
    die($json_string);
}
$appid = '1101326786';
$steps = isset($_GET['steps']) ? $_GET['steps'] : $_POST['steps'];
$openid = isset($_GET['openid']) ? $_GET['openid'] : $_POST['openid'];
$access_token = isset($_GET['access_token']) ? $_GET['access_token'] : $_POST['access_token'];
$arr = array(
            array(
                'time' => time(),
                'distance' => floor(intval($steps) / 2),
                'steps' => intval($steps),
                'type' => 1,
                'duration' => 0,
                'calories' => 0
            )
        );
$json_string = json_encode($arr);
$key = getKey($json_string);
$post_data = array();
$post_data['access_token'] = $access_token;
$post_data['oauth_consumer_key'] = $appid;
$post_data['openid'] = $openid;
$post_data['pf'] = 'qzone';
$post_data['data'] = $json_string;
$post_data['format'] = 'json';
$post_data['key'] = $key;
$post_data["version"] = '1.1';
$str = "";
foreach ($post_data as $k => $v) {
    $str.= urlencode($k).'='.urlencode($v).'&';
}
$post_data = substr($str,0,-1);
$post_url = 'https://openmobile.qq.com/v3/health/report_health_data';
$response = request_post($post_url,$post_data);
$rep = json_decode($response,true);
if ($rep['ret'] != 0) {
    $arr = array('ret' => $rep['ret'],'msg' => 'QQ运动刷步失败!原因:'.$rep['msg']);
    $json_string = json_encode($arr,JSON_UNESCAPED_UNICODE);
    die($json_string);
}
$arr = array('ret' => 0,'msg' => 'QQ运动刷步成功!');
$json_string = json_encode($arr,JSON_UNESCAPED_UNICODE);
die($json_string);
?>
END
文章标题:悦动圈QQ运动修改PHP源码
本文链接:https://yowal.cn/archives/10.html
版权说明:若无注明,本文皆枫岚剥壳 - 一个乐于分享的地方原创,转载请保留文章出处。
作品采用:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。
最后修改:2021 年 09 月 11 日 08 : 31 PM