"client_credentials", "client_id" => $clientId, "client_secret" => $clientSecret, "timestamp" => $timestamp, "sign" => $sign, "id" => sprintf("%04d%04d", rand(1, 9999), rand(1, 9999)) ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://open-api.yilianyun.net/oauth/oauth"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($tokenParams)); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $resTokenStr = curl_exec($ch); curl_close($ch); echo "Token 接口返回: " . $resTokenStr . "\n\n"; $resToken = json_decode($resTokenStr, true); if (isset($resToken["body"]["access_token"])) { $accessToken = $resToken["body"]["access_token"]; echo "获取 AccessToken 成功: " . $accessToken . "\n\n"; echo "========== 2. 发送易联云打印小票指令 ==========\n"; $content = "小众厨房设备商城\n"; $content .= "-- 测试订单 --\n"; $content .= "--------------------------------\n"; $content .= "订单编号:" . "TEST" . date("YmdHis") . "\n"; $content .= "下单时间:" . date("Y-m-d H:i:s") . "\n"; $content .= "--------------------------------\n"; $content .= "商品名称 数量 单价\n"; $content .= "商用切菜机(测试) 1 ¥69.00\n"; $content .= "隔热垫(测试) 2 ¥15.00\n"; $content .= "--------------------------------\n"; $content .= "合计金额:¥99.00 元\n"; $content .= "客户姓名:测试用户\n"; $content .= "联系电话:13984283762\n"; $content .= "送货地址:贵州省修文县城内配送点\n"; $content .= "--------------------------------\n"; $content .= "https://chufang.gynhc.com\n"; $content .= "谢谢惠顾,欢迎再次光临!\n"; $printTs = time(); $printSign = md5($clientId . $printTs . $clientSecret); $printParams = [ "client_id" => $clientId, "access_token" => $accessToken, "machine_code" => $machineCode, "content" => $content, "origin_id" => "TEST" . date("YmdHis"), "sign" => $printSign, "timestamp" => $printTs, "id" => sprintf("%04d%04d", rand(1, 9999), rand(1, 9999)) ]; $ch2 = curl_init(); curl_setopt($ch2, CURLOPT_URL, "https://open-api.yilianyun.net/printer/printindex"); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch2, CURLOPT_POST, 1); curl_setopt($ch2, CURLOPT_POSTFIELDS, http_build_query($printParams)); curl_setopt($ch2, CURLOPT_TIMEOUT, 10); curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false); $resPrintStr = curl_exec($ch2); curl_close($ch2); echo "打印接口返回: " . $resPrintStr . "\n"; } else { echo "获取 AccessToken 失败,请检查开发者ID与密钥。\n"; }