ottpay境外支付

        $price = $price * 100;
        $merchant = config('wx.merchant');
        $operator_id = config('wx.operator_id');
        $app_id = config('wx.userAppid');
        $url = config('wx.backurl');
        $wechatOrder = [
            'action' => 'MAPPPAY',
            'version' => '1.1',
            'merchant_id' => $merchant,
            'data' => [
                'order_id' => $sn,
                'operator_id' => $operator_id,
                'amount' => "$price",
                'biz_type' => 'WECHATPAY',
                'app_id' => $app_id,
                'open_id' => $user['openid'],
                'call_back_url' => $url,
            ],
        ];
        //境外支付
        $response = ottPay($wechatOrder);
        $res = json_decode($response);
        if ($res->rsp_code == 'SUCCESS') {
            $signjm = strtoupper(json_decode($response, true)["md5"] . "90B2E01C5DD08EE9");
            $keyjm = strtoupper(substr(md5($signjm), 8, 16));
            $d = base64_decode(json_decode($response, true)["data"]);
            $response = openssl_decrypt($d, 'AES-128-ECB', $keyjm, OPENSSL_RAW_DATA, false);
            $result = json_decode($response);
            $result->code = 0;
            return $result;
        } else {
            $res->code = 1;
            // $res = json_encode($res);
            return $res;
        }
  function ottPay($data)
{
    //签名
    ksort($data);
    ksort($data["data"]);
    $newdata = $data["data"];
    $str = "";
    foreach ($newdata as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $k1 => $v1) {
                $str .= $v1;
            }
        } else {
            $str .= $v;
        }
    }
    $signs = md5($str);
    $signs = strtoupper($signs);
    // $wechatOrder['md5'] = $sign;
    $sign = strtoupper($signs . "90B2E01C5DD08EE9");
    $key = strtoupper(substr(md5($sign), 8, 16));
    $ordata = json_encode($newdata);
    // $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-128-ECB'));
    // $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-128-ECB'));
    // dump($iv);die;
    $aes = openssl_encrypt($ordata, 'AES-128-ECB', $key, OPENSSL_RAW_DATA, false);
    $basesign = base64_encode($aes);
    $data["data"] = $basesign;
    $data["md5"] = $signs;
    $data = json_encode($data, JSON_UNESCAPED_UNICODE);
    //调用支付
    $url = 'https://frontapi.ottpay.com:443/process'; //接收xml数据的文件
    $header[] = "Content-type: application/json;charset=utf-8"; //定义content-type为xml,注意是数组
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 兼容本地没有指定curl.cainfo路径的错误
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $response = curl_exec($ch);
    return $response;
}

关注公众号技术谈论:靳某某的PHP爬坑之旅

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值