fork download
  1. <?php
  2.  
  3. function getTokenShopLevel($code, $partnerId, $partnerKey, $shopId) {
  4. $host="https://p...content-available-to-author-only...e.com";
  5. $path = "/api/v2/auth/token/get";
  6.  
  7. $timest = time();
  8. $body = array("code" => $code, "shop_id" => $shopId, "partner_id" => $partnerId);
  9.  
  10.  
  11. $baseString = sprintf("%s%s%s", $partnerId, $path, $timest);
  12. $sign = hash_hmac('sha256', $baseString, $partnerKey);
  13. $url = sprintf("%s%s?partner_id=%s&timestamp=%s&sign=%s", $host, $path, $partnerId, $timest, $sign);
  14.  
  15. print_r($url);exit;
  16.  
  17. $c = curl_init($url);
  18. curl_setopt($c, CURLOPT_POST, 1);
  19. curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($body));
  20. curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  21. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  22. $resp = curl_exec($c);
  23. echo "raw result: $resp";
  24.  
  25. $ret = json_decode($resp, true);
  26. $accessToken = $ret["access_token"];
  27. $newRefreshToken = $ret["refresh_token"];
  28. echo "\naccess_token: $accessToken, refresh_token: $newRefreshToken raw: $ret"."\n";
  29. return $ret;
  30. }
  31. getTokenShopLevel('6a666c5a676866444e616b7144765479',2000890, '596e485762537a6d4144484b67414a6d4f646c7176687a4662746e4662797456' ,97335446)
  32. ?>
  33.  
Success #stdin #stdout 0.03s 26200KB
stdin
Standard input is empty
stdout
{"code":"6a666c5a676866444e616b7144765479","shop_id":97335446,"partner_id":2000890}https://p...content-available-to-author-only...e.com/api/v2/auth/token/get?partner_id=2000890&timestamp=1748679925&sign=5b86053333f78e5fab1ce509b84397c065d06de6233caf5402ae12dc66cbbee5