chengkun
2025-08-14 6ba838a754c2f07754210d41f3afe650585dcd94
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
 
 
namespace Alipay\EasySDK\Test\marketing\openlife;
 
 
use Alipay\EasySDK\Kernel\Factory;
use Alipay\EasySDK\Marketing\OpenLife\Models\Article;
use Alipay\EasySDK\Marketing\OpenLife\Models\Context;
use Alipay\EasySDK\Marketing\OpenLife\Models\Keyword;
use Alipay\EasySDK\Marketing\OpenLife\Models\Template;
use Alipay\EasySDK\Test\TestAccount;
use PHPUnit\Framework\TestCase;
 
class ClientTest extends TestCase
{
    public function __construct($name = null, array $data = [], $dataName = '')
    {
        parent::__construct($name, $data, $dataName);
        $account = new TestAccount();
        Factory::setOptions($account->getTestCertAccount());
    }
 
    public function testCreateImageTextContent()
    {
        $result = Factory::marketing()->openLife()->createImageTextContent("标题",
            "http://dl.django.t.taobao.com/rest/1.0/image?fileIds=hOTQ1lT1TtOjcxGflvnUXgAAACMAAQED",
            "示例", "T", "activity", "满100减10",
            "关键,热度", "13434343432,xxx@163.com");
        $this->assertEquals('10000', $result->code);
        $this->assertEquals('Success', $result->msg);
    }
 
    public function testModifyImageTextContent()
    {
        $result = Factory::marketing()->openLife()->modifyImageTextContent(
            "20190510645210035577f788-d6cd-4020-9dba-1a195edb7342", "新标题",
            "http://dl.django.t.taobao.com/rest/1.0/image?fileIds=hOTQ1lT1TtOjcxGflvnUXgAAACMAAQED",
            "新示例", "T", "activity", "满100减20",
            "关键,热度", "13434343432,xxx@163.com");
        if ($result->code == '10000') {
            $this->assertEquals('10000', $result->code);
            $this->assertEquals('Success', $result->msg);
        } else {
            $this->assertEquals('40004', $result->code);
            $this->assertEquals('Business Failed', $result->msg);
            $this->assertEquals('PUB.MSG_BATCH_SD_OVER', $result->subCode);
            $this->assertEquals('批量发送消息频率超限', $result->subMsg);
        }
 
    }
 
    public function testSendText()
    {
        $result = Factory::marketing()->openLife()->sendText("测试");
        if ($result->code == '10000') {
            $this->assertEquals('10000', $result->code);
            $this->assertEquals('Success', $result->msg);
        } else {
            $this->assertEquals('40004', $result->code);
            $this->assertEquals('Business Failed', $result->msg);
            $this->assertEquals('PUB.MSG_BATCH_SD_OVER', $result->subCode);
            $this->assertEquals('批量发送消息频率超限', $result->subMsg);
        }
    }
 
    public function testSendImageText()
    {
        $article = new Article();
        $article->actionName = '测试';
        $article->desc = '测试';
        $article->title = '测试';
        $article->imageUrl = 'http://dl.django.t.taobao.com/rest/1.0/image?fileIds=hOTQ1lT1TtOjcxGflvnUXgAAACMAAQED';
        $article->url = 'https://docs.open.alipay.com/api_6/alipay.open.public.message.total.send';
        $result = Factory::marketing()->openLife()->sendImageText((array)$article);
        if ($result->code == '10000') {
            $this->assertEquals('10000', $result->code);
            $this->assertEquals('Success', $result->msg);
        } else {
            $this->assertEquals('40004', $result->code);
            $this->assertEquals('Business Failed', $result->msg);
            $this->assertEquals('PUB.MSG_BATCH_SD_OVER', $result->subCode);
            $this->assertEquals('批量发送消息频率超限', $result->subMsg);
        }
    }
 
    public function testSendSingleMessage()
    {
        $keyword = new Keyword();
        $keyword->color = "#85be53";
        $keyword->value = "HU7142";
 
        $context = new Context();
        $context->headColor = "#85be53";
        $context->url = "https://docs.open.alipay.com/api_6/alipay.open.public.message.single.send";
        $context->actionName = "查看详情";
        $context->keyword1 = $keyword;
        $context->keyword2 = $keyword;
        $context->first = $keyword;
        $context->remark = $keyword;
 
        $template = new Template();
        $template->templateId = "e44cd3e52ffa46b1a50afc145f55d1ea";
        $template->context = $context;
 
        $result = Factory::marketing()->openLife()->sendSingleMessage("2088002656718920", $template);
 
        $this->assertEquals('10000', $result->code);
        $this->assertEquals('Success', $result->msg);
    }
 
    public function testRecallMessage()
    {
        $result = Factory::marketing()->openLife()->recallMessage("201905106452100327f456f6-8dd2-4a06-8b0e-ec8a3a85c46a");
 
        $this->assertEquals('10000', $result->code);
        $this->assertEquals('Success', $result->msg);
    }
 
    public function testSetIndustry()
    {
        $result = Factory::marketing()->openLife()->setIndustry(
            "10001/20102", "IT科技/IT软件与服务",
            "10001/20102", "IT科技/IT软件与服务");
 
        if ($result->code == '10000') {
            $this->assertEquals('10000', $result->code);
            $this->assertEquals('Success', $result->msg);
        } else {
            $this->assertEquals('40004', $result->code);
            $this->assertEquals('Business Failed', $result->msg);
            $this->assertEquals('3002', $result->subCode);
            $this->assertEquals('模板消息行业一月只能修改一次', $result->subMsg);
        }
    }
 
    public function testGetIndustry()
    {
        $result = Factory::marketing()->openLife()->getIndustry();
        $this->assertEquals('10000', $result->code);
        $this->assertEquals('Success', $result->msg);
        $this->assertEquals('IT科技/IT软件与服务', $result->primaryCategory);
        $this->assertEquals('IT科技/IT软件与服务', $result->secondaryCategory);
    }
}