Açıklama Yok

Order.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/12/5
  6. * Time: 15:07
  7. */
  8. namespace App;
  9. use Illuminate\Database\Eloquent\Model;
  10. class Order extends Model
  11. {
  12. public $timestamps = false;
  13. protected $table = "order";
  14. public static function olist(){
  15. $result = Order::orderBy('id', 'desc')->get();
  16. return json_decode(json_encode($result),true);
  17. }
  18. public static function mjOrderAdd($orderList){
  19. $orderList["method"] = "maijiayun.order.add";
  20. var_dump($orderList);exit;
  21. $result = self::mjApi($orderList);
  22. return $result;
  23. }
  24. public static function mjApi($params = array()){
  25. echo 1;
  26. $accessKey = "B1E69297B5DA44DAB35099A5F28F41D9"; //erp 生成的 accessKey
  27. $accessSecret = "4sN2LbylhOglelMP";
  28. $params["timestamp"] = time()."000";
  29. $params["version"] = "v1";
  30. $reqparams = $params;
  31. ksort($reqparams);
  32. $sign = "";
  33. foreach($reqparams as $k=>$val){
  34. if(is_array($val)){
  35. $val = json_encode($val,320);
  36. }
  37. $sign.=$k.$val;
  38. }
  39. $params["accessKey"] = $accessKey;
  40. $params["token"] = strtoupper(sha1($accessKey.$sign.$accessSecret));
  41. $param = json_encode($params);
  42. echo 2;
  43. $ch = curl_init();
  44. $headers = array("Content-type:application/json;charset='utf-8'","Accept:application/json", "Cache-Control: no-cache", "Pragma: no-cache");
  45. curl_setopt($ch, CURLOPT_URL, "https://api.erp.maijiayun.cn"); //api 地址
  46. curl_setopt($ch, CURLOPT_POST, 1);
  47. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  48. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  49. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  50. curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  52. $response = curl_exec($ch);
  53. curl_close($ch);
  54. $response = json_decode($response, true);
  55. if (!$response || !is_array($response)) {
  56. return false;
  57. }
  58. if (!array_key_exists("isOk", $response)) {
  59. return false;
  60. } else {
  61. return $response;
  62. }
  63. }
  64. # 生成外部订单号
  65. public static function createOuterCode(){
  66. $order_sn = rand(100, 9999). substr(time(), 5, 5). rand(10, 9999);
  67. return $order_sn;
  68. }
  69. }