12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace refill\xinma;
- require_once(BASE_HELPER_RAPI_PATH . '/xinma/config.php');
- use refill;
- class RefillCallBack implements refill\IRefillCallBack
- {
- public function verify($params): bool
- {
- $sign = $this->sign($params);
- if ($params['sign'] == $sign) {
- return true;
- } else {
- return false;
- }
- }
- private function sign($params)
- {
- $key = config::APP_KEY;
- $user_name = config::USER_NAME;
- $content = "{$user_name}{$params['sys_order_id']}{$params['user_order_id']}{$key}";
- return md5($content);
- }
- public function notify($params)
- {
- $extractOfficialSn = function ($officialSnStr) {
- $officialSn = '';
- $matches = [];
- if (preg_match_all("/(\d+)/", $officialSnStr, $matches)) {
- foreach ($matches[1] as $item) {
- if (strlen($officialSn) < strlen($item)) {
- $officialSn = $item;
- }
- }
- }
- return $officialSn;
- };
- $status = intval($params['status']);
- $order_sn = $params['user_order_id'];
- $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
- if (empty($order_info)) {
- return [false, false, false, false, ''];
- }
- $order_id = $order_info['order_id'];
- if ($status === 200) {
- $official_sn = $extractOfficialSn($params['official_order_id']);
- $data['official_sn'] = $official_sn;
- Model('refill_order')->edit($order_id, $data);
- return [$order_id, true, false, true, $official_sn];
- }
- elseif ($status === 202) {
- return [$order_id, false, true, true, ''];
- }
- else {
- return [$order_id, false, false, false, ''];
- }
- }
- }
|