日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

ecstore mysql_微信查询订单API与商派ecstore订单状态对接

發布時間:2024/1/1 数据库 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ecstore mysql_微信查询订单API与商派ecstore订单状态对接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

提醒1:提交支付請求后微信會同步返回支付結果(后續說明異步的方法)。當返回結果為“系統錯誤”時,商戶系統等待5秒后調用【查詢訂單API】,查詢支付實際交易結果;當返回結果為“USERPAYING”時,商戶系統可設置間隔時間(建議10秒)重新查詢支付結果,直到支付成功或超時(建議30秒);

我用計劃任務做了查詢訂單API,根據訂單支付成功結果修改ecstore表的狀態。代碼如下:

/**

* 微信檢查訂單后,修改ecsotre表支付狀態

*/

Class checkPay{

public function __construct() {

date_default_timezone_set('Asia/Shanghai');

require_once("../config/config.php");

require_once("./dbase.php");

$this->dbase = new DB();

$this->dbase->connect(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME );

$this->is_log = "./logs/checkPay".date("Ymd").".log";

$this->wx['Appid'] = "*";

$this->wx['mch_id'] = "*";

$this->wx['key'] = "*";

}

public function getSdbOrder() {

$sql = "select order_id From sdb_b2c_orders where pay_status='0' and status='active'"; //pay_status表示未成功的

$rows= $this->dbase->get_rows($sql);

foreach ($rows as $key => $value) {

$cash_fee = $this->getWxOrderInfo($value['order_id']);

if ($cash_fee>0) {

$sql = "UPDATE `sdb_b2c_orders` SET `pay_status`='1', `payed`='{$cash_fee}',updatestats_tag='微信查帳修改' WHERE `order_id`={$value['order_id']}";

$this->dbase->query($sql);

$this->dbase->write_log("line 32: sql=".$sql,$this->is_log);

}

}

}

public function getWxOrderInfo($order_id) {

//微信的

$wx['Appid'] = $this->wx['Appid'];

$wx['mch_id'] = $this->wx['mch_id'];

//$wx['out_trade_no'] = "161222225332249";

$wx['out_trade_no'] = $order_id;

$wx['nonce_str'] = "abcdefg2abcdefg";

$wx['sign'] = $this->weiXinSign($wx);

$xmlStr = "";

$xmlStr .="{$wx['Appid']}";

$xmlStr .="{$wx['mch_id']}";

$xmlStr .="{$wx['nonce_str']}";

$xmlStr .="{$wx['out_trade_no']}";

$xmlStr .="{$wx['sign']}";

$xmlStr .="";

$sendpost = $this->sendpost($xmlStr);

$this->dbase->write_log("line 35: sendpost=".$sendpost,$this->is_log);

$postObj = simplexml_load_string($sendpost, 'SimpleXMLElement', LIBXML_NOCDATA);

$cash_fee= 0 ;

if ($postObj->trade_state =='SUCCESS' && $postObj->result_code=='SUCCESS' ) {

$cash_fee= sprintf("%.2f",$postObj->cash_fee/100);

}

return $cash_fee;

}

private function weiXinSign($wx) {

//微信的

$signArr = array();

$signArr['appid']= $this->wx['Appid'];

$signArr['mch_id']= $this->wx['mch_id'];

$signArr['nonce_str']=$wx['nonce_str'];

$signArr['out_trade_no']=$wx['out_trade_no'];

ksort($signArr);

$signArr2 = array();

foreach ($signArr as $key => $value) {

$signArr2[] = $key.'='.$value;

}

//去掉開頭的&并且進行MD5加密處理

$stringSignTemp = implode("&",$signArr2).'&key='.$this->wx['key'];

$sign = md5($stringSignTemp);

$sign = strtoupper($sign);

return $sign;

}

private function sendpost($data){

$url = "https://api.mch.weixin.qq.com/pay/orderquery";

$ch = curl_init();

$header[] = "Content-type: text/xml";//定義content-type為xml

curl_setopt($ch, CURLOPT_URL, $url); //定義表單提交地址

curl_setopt($ch, CURLOPT_POST, 1); //定義提交類型 1:POST ;0:GET

curl_setopt($ch, CURLOPT_HEADER, 0); //定義是否顯示狀態頭 1:顯示 ; 0:不顯示

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//定義請求類型

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//定義是否直接輸出返回流

curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //定義提交的數據,這里是XML文件

$result = curl_exec($ch);

curl_close($ch);//關閉

return $result;

}

}

$cPay = new checkPay();

$cPay->getSdbOrder();

使用計劃任務php checkPay.php 就可以了

上面還有一個工作沒有做,就是商派的ecstore沒有支付訂單記錄。這個后續有要求在加入。

分析一下,其實就是涉及下面的幾個表

INSERT INTO `zhihuimendian`.`sdb_ectools_order_bills` (`rel_id`, `bill_id`, `money`) VALUES ('161222200529117', '16122220052911700001', '33.900'); //插入支付表與order的關聯

UPDATE `sdb_b2c_orders` SET `pay_status`='1', `payed`='0.100',updatestats_tag='微信查帳修改' WHERE `order_id`=161222200529117; //修改支付狀態

總結

以上是生活随笔為你收集整理的ecstore mysql_微信查询订单API与商派ecstore订单状态对接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。