Here’s the fix, in the data.php file this fixed the importing of the file.
public static function new_get_freight( $args, $freight_ext ) {
$response = array(
‘status’ => ‘error’,
‘freight’ => array(),
‘code’ => ”,
‘from’ => ”,
);
try {
$_m_h5_tk = get_option( 'ald_token_m_h5_tk', 'xxxxxxxxxxxxxxxxxxxxxxxxxx' );
$_m_h5_tk_enc = get_option( 'ald_token_m_h5_tk_enc', 'xxxxxxxxxxxxxxxxxxxx' );
$args['ext'] = $freight_ext;
$args['quantity'] = $args['count'];
$args['clientType'] = 'pc';
$args['userScene'] = 'PC_DETAIL';
$freight = [];
$token = explode( '_', $_m_h5_tk )[0] ?? '';
$data = wp_json_encode( $args );
$sign_response = wp_remote_post( 'https://ald.villatheme.com/villatheme-ald-get-signature', [
'body' => [
'data' => $data,
'token' => $token,
]
] );
if ( is_wp_error( $sign_response ) ) {
error_log( 'Sign response error: ' . $sign_response->get_error_message() );
return $response;
}
$sign_response_body = wp_remote_retrieve_body( $sign_response );
$sign_response = json_decode( $sign_response_body, true );
if ( !is_array( $sign_response ) || empty( $sign_response['sign'] ) || empty( $sign_response['time'] ) ) {
error_log( 'Invalid sign response format or missing data.' );
return $response;
}
$sign = $sign_response['sign'];
$time = $sign_response['time'];
$url = "https://acs.aliexpress.com/h5/mtop.aliexpress.itemdetail.queryexpression/1.0/?jsv=2.5.1&appKey=12574478&t={$time}&sign={$sign}&api=mtop.aliexpress.itemdetail.queryExpression&v=1.0&type=originaljson&dataType=jsonp";
$cookies = [new WP_Http_Cookie( array( 'name' => '_m_h5_tk', 'value' => $_m_h5_tk ) ),
new WP_Http_Cookie( array( 'name' => '_m_h5_tk_enc', 'value' => $_m_h5_tk_enc ) )];
$request = wp_remote_post( $url, [
'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
"Accept" => 'application/json',
),
'body' => [ 'data' => $data ],
'cookies' => $cookies,
] );
if ( is_wp_error( $request ) ) {
error_log( 'Request error: ' . $request->get_error_message() );
return $response;
}
$body = wp_remote_retrieve_body( $request );
if ( is_wp_error( $body ) ) {
error_log( 'Body retrieval error: ' . $body->get_error_message() );
return $response;
}
$body = json_decode( $body, true );
if ( !is_array( $body ) || empty( $body['data'] ) ) {
error_log( 'Invalid response body format or missing data.' );
return $response;
}
$data = $body['data'] ?? [];
// Continue with your logic after ensuring $data is properly set...
// Your existing logic for processing $data...
} catch ( \Exception $e ) {
error_log( print_r( $e->getMessage(), true ) );
}
return $response;
}
-
This reply was modified 8 months ago by nzfade.