1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\common\service;
- use addons\epay\library\Service;
- use jdpay\com\jdjr\pay\demo\common\SignUtil;
- use jdpay\com\jdjr\pay\demo\common\TDESUtil;
- class Jdpay{
- protected $appid;
- protected $merchantNo;
- protected $desKey;
- public function __construct()
- {
- $this->appid=config('site.appId');
- $this->merchantNo=config('site.merchantNo');
- $this->desKey=config('site.jd_desKey');
- }
- public function order($orderNo,$amount,$desc){
- $arr=[
- 'version'=>'V1.0.0',
- 'appId'=>$this->appid,
- 'merchantNo'=>$this->merchantNo,
- 'orderId'=>$orderNo,
- 'amount'=>bcmul($amount,100,0),
- 'virtualType'=>'01',
- 'sourcePlat'=>'h5',
- 'tradeName'=>$desc,
- 'outTradeIp'=>request()->ip(),
- 'successNotifyUrl'=>Service::notifyUrlJd($orderNo),
- 'expireTime'=>'3600',
- 'outTradePort'=>(string)request()->port(),
- ];
- $newArr=$arr;
- $key=base64_decode($this->desKey);
- foreach ($newArr as $key=>$item){
- if(in_array($key,['merchantNo'])){
- continue;
- }
- $newArr[$key]=TDESUtil::encrypt2HexStr($key,$item);
- }
- $query=[
- 'merchantNo'=>$this->merchantNo,
- 'cipherJson'=>TDESUtil::encrypt2HexStr($key,json_encode($newArr)),
- 'sign'=>SignUtil::signWithoutToHex($arr,[]),
- ];
- $link='https://payx.jd.com/cashier/h5/saveOrder?'.http_build_query($query);
- return [
- 'pay_url'=>$link,
- 'data'=>$newArr
- ];
- }
- }
|