123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use Aws\Sns\SnsClient;
- use Aws\Exception\AwsException;
- /**
- * 示例接口
- */
- class Demo extends Api
- {
- //如果$noNeedLogin为空表示所有接口都需要登录才能请求
- //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
- //如果接口已经设置无需登录,那也就无需鉴权了
- //
- // 无需登录的接口,*表示全部
- protected $noNeedLogin = ['*'];
- // 无需鉴权的接口,*表示全部
- protected $noNeedRight = ['*'];
- /**
- * 测试方法
- *
- * @ApiTitle (测试名称)
- * @ApiSummary (测试描述信息)
- * @ApiMethod (POST)
- * @ApiRoute (/api/demo/test/id/{id}/name/{name})
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="id", type="integer", required=true, description="会员ID")
- * @ApiParams (name="name", type="string", required=true, description="用户名")
- * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
- * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
- * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
- * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
- * @ApiReturn ({
- 'code':'1',
- 'msg':'返回成功'
- })
- */
- public function test1(){
- $SnSclient = new SnsClient([
- 'profile' => 'default',
- 'region' => 'us-east-1',
- 'version' => '2010-03-31'
- ]);
- $subscription_token = 'arn:aws:sns:us-east-1:111122223333:MyTopic:123456-abcd-12ab-1234-12ba3dc1234a';
- $topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
- try {
- $result = $SnSclient->confirmSubscription([
- 'Token' => $subscription_token,
- 'TopicArn' => $topic,
- ]);
- var_dump($result);
- } catch (AwsException $e) {
- // output error message if fails
- error_log($e->getMessage());
- }
- }
- public function test(){
- $out_trade_no = createUniqueNo('Test');
- $money = '1';
- $notifyurl = config('notify_cdnurl');
- $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
- dump($rs);
- //payorder 保存 $rs['id'] 为 payment_request_id
- }
- public function hitpay_payment($out_trade_no,$money,$notifyurl)
- {
- $return = [
- 'status' => false,
- 'msg' => '',
- 'url' => '',
- 'id' => 0,
- ];
- $apiKey = config('hitpay.apikey');
- try {
- $hitPayClient = new \HitPay\Client($apiKey, true);
- $request = new \HitPay\Request\CreatePayment();
- $request->setAmount($money)
- ->setCurrency('SGD')
- ->setPaymentMethods(['paynow_online','card'])
- ->setPurpose('Elin Dance Studio')
- ->setWebhook($notifyurl)
- ->setReferenceNumber($out_trade_no);
- $result = $hitPayClient->createPayment($request);
- $return['status'] = true;
- $return['url'] = $result->getUrl();
- $return['id'] = $result->getId();
- //print_r($result);
- /*$data = $hitPayClient->getPaymentStatus($result->getId());
- dump($data);
- dump($data->status);*/
- /*$data = $hitPayClient->deletePaymentRequest($data->getId());
- print_r($data);*/
- } catch (\Exception $e) {
- $return['msg'] = $e->getMessage();
- }
- return $return;
- }
- public function qixunyun_sms($mobile,$code){
- //配置
- $config = config('qixunyun_sms');
- $name = $config['name'];
- $password = $config['password'];
- $signname = $config['signname'];
- $url = 'https://api.hnsls5g.com/eums/sms/utf8/send.do';
- $seed = date('YmdHis');
- $content = '【'.$signname.'】Your verification Code is : ' . $code;
- $data = [
- 'name' => $name,
- 'seed' => $seed,
- 'key' => strtolower(md5(strtolower(md5($password)).$seed)),
- 'dest' => $mobile,
- 'content' => $content,
- ];
- $params = http_build_query($data);
- $url = $url.'?'.$params;
- $rs = curl_get($url);
- //dump($rs);
- //return $rs;
- //结果处理
- //$rs = 'error:111';
- //$rs = 'success:122617370809355265322';
- if(strpos($rs,'error:') === 0){
- $code = substr($rs,6);
- return $this->qixunyun_error($code);
- }
- if(strpos($rs,'success:') === 0){
- return true;
- }
- return '短信发送失败了';
- }
- public function newsms2(){
- $rs = $this->qixunyun_sms('18560505277','123456');
- dump($rs);
- }
- private function qixunyun_error($code){
- $array = [
- '101' => '缺少name参数',
- '102' => '缺少seed参数',
- '103' => '缺少key参数',
- '104' => '缺少dest参数',
- '105' => '缺少content参数',
- '106' => 'seed错误',
- '107' => 'key错误',
- '108' => 'ext错误',
- '109' => '内容超长',
- '110' => '模板未备案',
- '111' => '无签名',
- '112' => '缺少pk_total参数',
- '113' => '签名不合法',
- '114' => '定时时间格式错误',
- '115' => '定时时间范围错误',
- '116' => '不支持HTTP',
- '201' => '无对应账户',
- '202' => '账户暂停',
- '203' => '账户删除',
- '204' => '账户IP没备案',
- '205' => '账户无余额',
- '206' => '密码错误',
- '301' => '无对应产品',
- '302' => '产品暂停',
- '303' => '产品删除',
- '304' => '产品不在服务时间',
- '305' => '无匹配通道',
- '306' => '通道暂停',
- '307' => '通道已删除',
- '308' => '通道不在服务时间',
- '309' => '未提供短信服务',
- '401' => '屏蔽词',
- '500' => '查询间隔太短',
- '999' => '其他错误',
- ];
- $error = isset($array[$code]) ? $array[$code] : '短信发送失败';
- return $error;
- }
- public function whatsapp(){
- $account_id = '657a5348-b28f-4736-8c76-6c47f4b20e4e';
- $daibi = '350448a7-e8bc-4310-8d5b-db3518a5d05e';
- $url = 'https://gw.cmtelecom.com/v1.0/message';
- $client = new \CMText\TextClient('your-api-key');
- echo json_encode(
- $client->SendMessage('Message_Text', 'CM.com', [ '15866999421' ], 'Your_Reference')
- );
- }
- }
|