Code Duplication    Length = 27-27 lines in 2 locations

src/phpsms/lib/Ucpaas.php 2 locations

@@ 380-406 (lines=27) @@
377
     * @return mixed|string
378
     * @links http://www.ucpaas.com/page/doc/doc_rest2-8.jsp
379
     */
380
    public function chargeClient($appId, $clientNumber, $chargeType, $charge, $type = 'json')
381
    {
382
        $url = self::BaseUrl . self::SoftVersion . '/Accounts/' . $this->accountSid . '/chargeClient?sig=' . $this->getSigParameter();
383
        if ($type === 'json') {
384
            $body_json = array('client' => array(
385
                'appId'        => $appId,
386
                'clientNumber' => $clientNumber,
387
                'chargeType'   => $chargeType,
388
                'charge'       => $charge,
389
            ));
390
            $body = json_encode($body_json);
391
        } elseif ($type === 'xml') {
392
            $body_xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
393
                        <client>
394
                            <clientNumber>' . $clientNumber . '</clientNumber>
395
                            <chargeType>' . $chargeType . '</chargeType>
396
                            <charge>' . $charge . '</charge>
397
                            <appId>' . $appId . '</appId>
398
                        </client>';
399
            $body = trim($body_xml);
400
        } else {
401
            throw new Exception('只能json或xml,默认为json');
402
        }
403
        $data = $this->getResult($url, $body, $type, 'post');
404
405
        return $data;
406
    }
407
408
    /**
409
     * @param $appId
@@ 500-526 (lines=27) @@
497
     * @return mixed|string
498
     * @links http://www.ucpaas.com/page/doc/doc_rest4-1.jsp
499
     */
500
    public function templateSMS($appId, $to, $templateId, $param = null, $type = 'json')
501
    {
502
        $url = self::BaseUrl . self::SoftVersion . '/Accounts/' . $this->accountSid . '/Messages/templateSMS?sig=' . $this->getSigParameter();
503
        if ($type === 'json') {
504
            $body_json = array('templateSMS' => array(
505
                'appId'      => $appId,
506
                'templateId' => $templateId,
507
                'to'         => $to,
508
                'param'      => $param,
509
            ));
510
            $body = json_encode($body_json);
511
        } elseif ($type === 'xml') {
512
            $body_xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
513
                        <templateSMS>
514
                            <templateId>' . $templateId . '</templateId>
515
                            <to>' . $to . '</to>
516
                            <param>' . $param . '</param>
517
                            <appId>' . $appId . '</appId>
518
                        </templateSMS>';
519
            $body = trim($body_xml);
520
        } else {
521
            throw new Exception('只能json或xml,默认为json');
522
        }
523
        $data = $this->getResult($url, $body, $type, 'post');
524
525
        return $data;
526
    }
527
}
528